I want to grab the all global key events on linux using JNA same as window hooks. following is the code:
package pack.tracker.services;
//import sun.awt.X11.XEvent;
//import com.jscape.inet.ssh.transport.KeyCreator;
import com.sun.jna.examples.unix.X11;
import com.sun.jna.examples.unix.X11.Display;
import com.sun.jna.examples.unix.X11.Window;
import com.sun.jna.examples.unix.X11.XEvent;
public class JNATest {
X11 x = X11.INSTANCE;
Window window;
Display display = x.XOpenDisplay("0");
XEvent ev = new XEvent();
public JNATest() {
System.out.println("hi");
// TODO Auto-generated constructor stub
String keyString = "F3" ;
Display display = x.XOpenDisplay(null);
XEvent ev = new XEvent();
window = x.XDefaultRootWindow(display);
for(;;){
x.XNextEvent(display, ev);
if(ev.type == X11.KeyPress){
System.out.println("KeyPressed");
}
else{
System.out.println("ok");
}
}
}
public static void main(String s[]){
new JNATest();
}
}
I donot know whats going wrong. I am unable to use XGrabKeyboard. Please help me out.
Thanks and regards, Vivek Birdi