Trap all keys - please help...

Hello:

I am writing a Java application for people with mental disorders. While working with the application, they should be able to press ANY (and I mean ANY) key on the keyboard to move forward. I was able to work it out using KeyListener, however when the user presses Windows key or Sleep key the action associated with them is performed BEFORE I get a keyDown event.

Actually, the dialog is opened on the screen , or Windows Start Dialog, when Windows key is pressed, or Hibernate dialog, when the Sleep key is pressed, and then my application continues to work.

It is very irritating for this kind of users - they just don't know how to close this dialog or what to do at all, and got stuck.

Besides that application works just fine, however we cannot release it with this problem still here.

Is there any way to trap these keys ? I just couldn't find their names for key mapping, I am absolutely clueless.

Any links, samples, ideas - your input is greatly appreciated.

Jose

[1033 byte] By [chickenmad] at [2007-9-30 20:10:48]
# 1
As far as I know, certain keys / combinations of keys are going to only be seen by the OS first and not notify you about, such as Ctrl-Alt-Del for one, if running on Windows. I think your "requirement" is wonky.
warnerja at 2007-7-7 0:56:24 > top of Java-index,Java Essentials,Java Programming...
# 2
It is not a stupid requirement, it is a reality, while working with such kind of people, what can I do ? :-(
chickenmad at 2007-7-7 0:56:24 > top of Java-index,Java Essentials,Java Programming...
# 3
>> what can I do ?Nothing (change your requirements, remove the sleep key from the keyboard, etc.).
levi_h at 2007-7-7 0:56:24 > top of Java-index,Java Essentials,Java Programming...
# 4
Thanks you both for answers. What about a platform dependent solution ? I can use keyboard hooks on Windows,my background is basically c/c++ and I am relatively new to Java, so the question is : will such "hacker" code compile with Java as a native code ?
chickenmad at 2007-7-7 0:56:24 > top of Java-index,Java Essentials,Java Programming...
# 5

> Thanks you both for answers. What about a platform

> dependent solution ? I can use keyboard hooks on

> Windows,my background is basically c/c++ and I am

> relatively new to Java, so the question is : will such

> "hacker" code compile with Java as a native code ?

I believe (could be wrong, but this is pretty much an educated guess) that even if you were to use the low-level API (SetWindowsHookEx) it still would not "see" certain keystrokes, such as the already-mentioned Ctrl-Alt-Del combo. You're not supposed to be able to, so that it is "guaranteed" that when a user presses that combo, the REAL windows dialog is displayed instead of allowing a hacker to put up a dummy dialog and be able to determine the user's password when he/she typed it into such a dialog box.

warnerja at 2007-7-7 0:56:24 > top of Java-index,Java Essentials,Java Programming...
# 6
so, no hope :-(((Thanks, anyway... I am really new in these forums, should I still give dukes for the answer "no, you couldn't" ? Just don't know , no offensive ....
chickenmad at 2007-7-7 0:56:24 > top of Java-index,Java Essentials,Java Programming...
# 7

> so, no hope :-(((

> Thanks, anyway... I am really new in these forums,

> should I still give dukes for the answer "no, you

> couldn't" ? Just don't know , no offensive ....

Well, what else are you going to do with them? And actually your questions were answered. Give them or retract them, it doesn't really matter much - they're not good for anything really. The main thing is you said "thanks anyway".

warnerja at 2007-7-7 0:56:24 > top of Java-index,Java Essentials,Java Programming...
# 8
Not sure, but you might be able to use an AWTEventListener. Here is an [url http://forum.java.sun.com/thread.jsp?forum=57&thread=289887]example[/url] that listens for MouseEvents.
camickr at 2007-7-7 0:56:25 > top of Java-index,Java Essentials,Java Programming...
# 9
Thanks, that's exactly what I was trying to do - using ActionListener. It helps for some other "special" keys, but as for Windows and Sleep key - I just could find their scan codes - when I got keyDown event, the keyCode field of the KeyEvent object I get, is always 0.
chickenmad at 2007-7-7 0:56:25 > top of Java-index,Java Essentials,Java Programming...
# 10
Hello:Just in case somebody is interested , I was able to solve this problem on the Windows platform, using Paul DiLascia's excellent article http://msdn.microsoft.com/msdnmag/issues/02/09/cqa/default.aspx:AC
chickenmad at 2007-7-7 0:56:25 > top of Java-index,Java Essentials,Java Programming...