kristian / system-hook

Global Keyboard / Mouse Hook for Java applications.
MIT License
270 stars 48 forks source link

about a keyTyped-like method #11

Closed mhashim6 closed 7 years ago

mhashim6 commented 7 years ago

pressing shift or caps doesn't affect the state of entered chars (they aren't capitalized) , I managed to solve this in my testing/launcher class, I wonder if this's possible to implement in low-level? also in GUI components there's a keyTyped method that handles the typed characters, is this possible to implement here? thanks.

kristian commented 7 years ago

Hello Muhammad, thanks for considering using the system-hook library. This library is focussed on detecting key-presses. Determining the character pressed for some keys typed, would involve much more tricky stuff to be done, such as keyboard layout mapping and multi-key handling (e.g. for Chinese, one unicode character might be "composed" by multiple key presses). I wanted to keep the library as simple as possible for it's core purpose (detecting keys, not characters). Therefore I decided to only add a very rudimentary character handling by using Windows ToUnicode function on each key pressed and passing it to the GlobalKeyEvent.

Implementing a basic upper case handling in your event handler should be as easy as:

char keyChar = event.getKeyChar();
if(event.isShiftPressed())
  keyChar = Character.toUpperCase(keyChar);
System.out.println(keyChar);

Adding a propper keyTyped event to the library, would require a lot more logic to be done in the low-level part, which I don't think makes sense for this library. There are other libraries out there, focussing on exactly that. Hope this helps anyways. Regards, Kristian