I\'m trying to write a resolution selection dialog that pops up when a program first starts up. To prevent boring the user, I want to implement the fairly standard feature t
The original question seems to be not answered. The proposed method determines the locking key state like CapsLock, ScrollLock, etc. So it would not work for Alt pressed state.
Consider the following code:
com.sun.jna.platform.KeyboardUtils.isPressed(java.awt.event.KeyEvent.VK_ALT);
The only problem is that this class is an internal Sun's JDK class and not likely to be available in any other JVM. Depend on your project it may or may not be acceptable.
Internally it calls into User32.DLL on Windows:
User32.INSTANCE.GetAsyncKeyState(...)