kristian / system-hook

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

Is there a way to disable keys? #51

Closed osaulonery closed 9 months ago

osaulonery commented 9 months ago

I was trying something like that, but doesnt have consume.

public void keyPressed(GlobalKeyEvent event) { int keyCode = event.getVirtualKeyCode(); if (keyCode == 0x31 || keyCode == 0x32) { event.consume(); } }

kristian commented 9 months ago

Events that are received from the native hook are added to a queue before they are processed, so there is no way of preventing the default behavior of the key press. Also in terms of the Windows API, this would be unreliable, as Windows treats key / mouse hooks as a chain, so it‘ll depend on where you are in the chain on what you can supress. Short answer: no you can unfortunately not consume the key.