使用 JNA 在 Linux 上使用 Xlib XnextEvent
我想使用 JNA 与窗口挂钩一样捕获 Linux 上的所有全局关键事件。以下是代码:
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();
}
}
我不知道出了什么问题。我无法使用 XGrabKeyboard。请帮帮我。
谢谢和问候, 维韦克·伯迪
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XGrabKeys 方法尚未在 JNA 中实现。您需要扩展 X11 库并定义方法,如下所示:
查看此站点 用于 Xlib 结构和方法。
如果您仍然无法在 JNA 中实现,请查看 JXGrabkey (http://sourceforge.net/projects/jxgrabkey/)。
The XGrabKeys method has not been implemented in JNA. You will need to extend the X11 library and define the method like so:
Have a look at this site for Xlib structures and methods.
If you are still unable to implement in JNA then have a look at JXGrabkey at(http://sourceforge.net/projects/jxgrabkey/).