views:

81

answers:

3

On Mac OS/X in both Firefox and Chrome, the mouse cursor disappears when I type. Is there anyway in javascript to prevent this behavior or to force the cursor to become visible again?

I'm using jquery for the keyboard handling:

  // keyboard handlers
  $(document).keydown(this.keydown);
  $(document).keyup(this.keyup);

...

keydown: function(evt) {
  var app = PGE_LIB.game();
  switch(evt.which) {
  case 'G'.charCodeAt(0):
    app.activateGrabTool();
    break;
  case 'S'.charCodeAt(0):
    $('#toolbar img').removeClass('activeTool');
    $('#scaleTool').addClass('activeTool');
    break;
  case app.ESC_KEY:
    app.deactivateTool();
    break;
  case app.SHIFT_KEY:
    app._shiftKeyDown = true; break;
  default:
    break;
  }
},
+6  A: 

This is expected behaviour in those browsers. Behaviour the users expect. There is, thankfully, no way to disable this.

Personally, I find many of the UI decision on OS X to be infuriating, but since it is standard behaviour in OS X, altering this would certainly go contrary to the user's expectations.

EDIT

I don't have a mac available to me at the moment, so I can:t test this, but see http://api.jquery.com/event.preventDefault/

you can use event.preventDefault() to alter default behaviour of some elements. It doesn't always work, and afaik the disappearing mouse cursor issue is an OS-wide behaviour, not browser specific.

Jonathan Fingland
Well, I appreciate the definitive answer, except for the 'thankfully' part. I'm developing a graphical design web app that uses keyboard input to switch between tools. So I need to change the mouse cursor from 'pointer' to 'move' or 'resize'. Currently, the cursor just disappears when changing tools, which is unacceptable. The current capabilities of web browsers would allow for development of all kinds of cool apps with great ease except for ridiculous limitations like this.
William Knight
@William, apologies for the use of the term. Perhaps another might have been subtler. My point was that browser makers have actually gotten a lot better about locking down some of these things. That:s what I was being thankful for. What you describe does indeed sound like an interesting, and useful application. Is the issue not so much "when I type", but rather how to capture keyboard input and prevent default actions?
Jonathan Fingland
The issue is that I have a selection of objects that I may want to move or resize and a UI convention where you can hit a 'g' or 's' key to 'grab' or 'scale' (just like Blender does it). Currently, when I hit one of those keys, the mouse cursor just disappears and the user has to move the mouse to get the cursor to show up. This doesn't happen in Mac apps such as the Gimp so presumably there is a low-level way to prevent cursor-hiding while typing on the mac. But not in browsers apparently.
William Knight
I take, then, that the `event.preventDefault()` did not get around this limitation.
Jonathan Fingland
@William, as a workaround, you can detect the cursor position and show the cursor as an image there temporarily until the next `mousemove`. Edit: but if you do this, please be sure for the sake of consistency to hide the cursor for Mac users on the *next* (unhandled) keystroke.
eyelidlessness
@eyelidlessness, this works on the assumption that the standard cursors haven't been altered by the users in any way.
Jonathan Fingland
Hey, that is a sweet idea! Thanks!
William Knight
@eyelidlessness: you should submit that image solution as an answer and I will accept it after testing it.
William Knight
@Jonathon Fingland: I haven't tried event.preventDefault(), will try that now.
William Knight
Adding a call to event.preventDefault() at the end of the keydown() handler did not prevent the mouse cursor from disappearing in Firefox.
William Knight
@Jonathan, I was assuming William is using custom cursors in the first place. If that's not the case, the image solution won't be consistent *anyway*, as different browsers use different standard cursors.
eyelidlessness
+1  A: 

If you're using custom cursors, when your key event fires, you can detect the cursor position and display an image in its place until the next mousemove. In this case, you should also hide the image for un-handled key events. And if you're not using custom cursors, be aware that you will probably be presenting some users with a different version of the standard cursor than their OS or browser or user-installed cursor set displays.

eyelidlessness
I'm now using custom cursors in my app and this approach completely solves the problem.
William Knight
A: 

Sorry, but you can't disable this built-in operating system feature through the browser.

screenshot

Kranu
Am I crazy or does this not work at all in Windows? The times I've had to use Windows for longish short-term periods, it's *never* worked.
eyelidlessness
@eye: It's always worked for me, although a couple programs (like games) that use custom cursors and text boxes don't work. I use Windows 7 and sometimes Windows XP.
Kranu