Javascript Global Keyboard Handling, Not Listening To AZ Keys?

I'm trying to use Javascript to intercept keyboard events, so I can do CMD-W for a "closed window" and something else inside the Flash application, so the browser will not be able to use them.

Well, I can listen to ALT, CTRL and CMD onKeyDown / onKeyPress, but I canโ€™t listen to anything ... Here is the code in the index.html file from the Flex project

<script language="JavaScript" type="text/javascript"> document.onkeydown = function(event) {applicationKeyboardHandler(event)} document.onkeypress = function(event) {applicationKeyboardHandler(event)} function applicationKeyboardHandler(event) { alert("Key Pressed") } </script> 
code>

I would like to make it listen to any keystroke, not just alt / ctrl / cmd. What am I missing?

0
javascript flex externalinterface
source share
3 answers

Like Tim, I think Flash / Flex swallows key events. Since Alt etc. They are meta-keys; they do not trigger a keystroke event in Flex and are passed to JS. On the other hand, some gestures (e.g. Ctrl + A on some browsers) cannot be received by Flash. I believe that for the same reason (security) they also cannot be handled by JS. Which key protected gestures are highly browser dependent.

The browser probably will not allow you to process CTRL-Q so that the user can always close his browser even when opening some malicious sites.

+2
source share

I believe the Flash movie handles key events and prevents them from spreading through the document tree. Why not handle events in Flash itself?

+1
source share

Are you sure Flash is not blocking it? Have you tried to run your code on a page without Flash?

You should try to bind events to a window, not a document.

+1
source share

All Articles