Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting mouse position in keyboard event

I'm trying to have a selection wheel appear when the user holds down the Shift key.

The wheel should be centred on the mouse's position.

However when I test this, pageX and clientX are both undefined on the event object.

Is it possible to get the mouse coordinates on a keyboard event?

like image 487
Niet the Dark Absol Avatar asked Sep 26 '11 23:09

Niet the Dark Absol


People also ask

How do I get my mouse cursor position?

Once you're in Mouse settings, select Additional mouse options from the links on the right side of the page. In Mouse Properties, on the Pointer Options tab, at the bottom, select Show location of pointer when I press the CTRL key, and then select OK.

Which event is triggered when you click any key on the keyboard?

The onkeypress event occurs when the user presses a key (on the keyboard).

What are the keyboard events in JavaScript?

There are three types of keyboard events: keydown , keypress , and keyup . For most keys, Gecko dispatches a sequence of key events like this: When the key is first pressed, the keydown event is sent. If the key is not a modifier key, the keypress event is sent.


1 Answers

No, simply track mousemove events and continuously save the current position in case you get a keyboard event.

like image 86
Daniel Brockman Avatar answered Oct 17 '22 00:10

Daniel Brockman