Skip to main content
Damon D Bell
Known Participant
February 4, 2016
Answered

Global keyboard event listener?

  • February 4, 2016
  • 1 reply
  • 752 views

Is it possible to create a global keyboard event listener that is not tied to a window, button, or any other UI element?  The best I've been able to come up with is adding the event listener to the window.  This only works if the window is active.  If the user clicks outside of the window then the keyboard listener does not work.  Also, when the dialog first appears, this won't work until after the user has made some type of interaction with the window.  What I want is to have some keyboard shortcuts for the user that work regardless of where they have clicked on the screen, even if the dialog window is not "active".  Is this possible?

Here is the code I am using for the keyboard listener for the window.

mywindow.addEventListener ("keydown", function (k) {keyListen(k)});

function keyListen(k){if(k.keyName=="Z"){alert("Do stuff here");}}

This topic has been closed for replies.
Correct answer cbuliarca

I don't think you can create global events listeners, as for the first appearance of the dialog I've solved that problem in my script: buliarca's scripts BCM_ExtendShortcuts UI by making a button active and putting the event listener to that button. One problem with attaching listeners to window is that in CC2015 the events can only be attached to controls and not to windows. Attaching to windows works in CS6...

1 reply

cbuliarcaCorrect answer
Inspiring
February 5, 2016

I don't think you can create global events listeners, as for the first appearance of the dialog I've solved that problem in my script: buliarca's scripts BCM_ExtendShortcuts UI by making a button active and putting the event listener to that button. One problem with attaching listeners to window is that in CC2015 the events can only be attached to controls and not to windows. Attaching to windows works in CS6...

Damon D Bell
Known Participant
February 5, 2016

OK, thanks.  That is what I thought but I was hoping I was wrong.  I think the latest release of CC2015.1.2 now works with events attached to the window.  At least it seems to work for me.  However, attaching to a button may make more sense anyway if the events are available right away.