Hiding the mouse cursor when idle using JavaScript

后端 未结 7 1840
灰色年华
灰色年华 2021-02-14 01:29

Is it possible to use JavaScript to set the cursor attribute to the property none if the mouse is inactive for a certain amount of time (say, five seco

7条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-14 02:34

    In my kiosk apps, to make sure no "pressed" characters are lost on a move out of screen-saver (they are usually sent to the PC via a bar code scanner or rfid reader) and to ensure the screen comes back on instantly, I use the following bits of code, along with a transparent cur cursor file, and disable all the screen saving/power saving options in the host OS. This works in Chrome 12, and probably many other browsers. I don't think there is any Chrome-specific code-- it's just the easiest thing to auto-launch into a kiosk-mode.

    The sloppy bits iterating through the INPUT elements are needed because those form parts will keep their default (typically white) background.

    If you use images, or colored text, or other such objects, you'll need to figure out how to deal with those. I'm just building data acquisition apps, so it's just black text up there on the screen. Turning the page background black makes the whole screen black, and prevents burn in.

    This could and should be done by applying various CSS bits via JS, but it works, well, and it's all in one spot in the code, so it's easy to paste around, say, to a place like this.

    
    

    onkeydown fires unSS is in the body so that every time a key press is seen it will reset the timer.

    
    
                                     
                  
提交回复
热议问题