/usr/share/doc/libjxgrabkey-java/example/JXGrabKeyTest.java is in libjxgrabkey-doc 0.3.2-9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import java.awt.event.KeyEvent;
import java.io.File;
import javax.swing.JOptionPane;
import jxgrabkey.HotkeyConflictException;
import jxgrabkey.HotkeyListener;
import jxgrabkey.JXGrabKey;
public class JXGrabKeyTest {
private static final int MY_HOTKEY_INDEX = 1;
private static boolean hotkeyEventReceived = false;
public static void main(String[] args) throws Exception {
//Load JXGrabKey lib
System.load(new File("lib/libJXGrabKey.so").getCanonicalPath());
//Enable Debug Output
JXGrabKey.setDebugOutput(true);
//Register some Hotkey
try{
//int key = KeyEvent.VK_K, mask = KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK;
int key = KeyEvent.VK_F2, mask = KeyEvent.ALT_MASK; //Conflicts on GNOME
JXGrabKey.getInstance().registerAwtHotkey(MY_HOTKEY_INDEX, mask, key);
}catch(HotkeyConflictException e){
JOptionPane.showMessageDialog(null, e.getMessage(), e.getClass().getName(), JOptionPane.ERROR_MESSAGE);
JXGrabKey.getInstance().cleanUp(); //Automatically unregisters Hotkeys and Listeners
//Alternatively, just unregister the key causing this or leave it as it is
//the key may not be grabbed at all or may not respond when numlock, capslock or scrollock is on
return;
}
//Implement HotkeyListener
HotkeyListener hotkeyListener = new jxgrabkey.HotkeyListener(){
public void onHotkey(int hotkey_idx) {
if (hotkey_idx != MY_HOTKEY_INDEX)
return;
hotkeyEventReceived = true;
}
};
//Add HotkeyListener
JXGrabKey.getInstance().addHotkeyListener(hotkeyListener);
//Wait for Hotkey Event
while(!hotkeyEventReceived){
Thread.sleep(1000);
}
// Shutdown JXGrabKey
JXGrabKey.getInstance().unregisterHotKey(MY_HOTKEY_INDEX); //Optional
JXGrabKey.getInstance().removeHotkeyListener(hotkeyListener); //Optional
JXGrabKey.getInstance().cleanUp();
}
}
|