适用于Linux Java Swing应用程序的Kiosk模式 [英] Kiosk mode for Linux Java Swing application

查看:177
本文介绍了适用于Linux Java Swing应用程序的Kiosk模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在[Ubuntu] Linux机器上禁用操作系统级键盘快捷键(例如Alt-Tab,Ctrl-Alt-Left / Right等)?我正在开发一个全屏Java Swing应用程序,并且不希望用户能够任意切换程序。仅仅切换永远在线标志是不够的;不允许用户切换工作区,迁移焦点或任何其他此类事物。在执行应用程序之前和之后,机器必须正常运行。谷歌表示,这将需要JNI或JNA,但我正在寻找更多的手持。

How can I disable OS-level keyboard shortcuts (e.g. Alt-Tab, Ctrl-Alt-Left/Right, etc.) on a [Ubuntu] Linux machine? I'm developing a full-screen Java Swing app and don't want the user to be able to task switch away from the program arbitrarily. It's not enough to toggle the "always on top" flag; users mustn't be allowed to switch workspaces, migrate focus or any other such things. The machine must function normally before and after the application is executed. Google says that this will require JNI or JNA but I'm looking for a bit more hand-holding.

推荐答案

没有必要尝试在您的应用程序中执行此操作,因为任何这些更改都需要由X11和/或窗口管理器处理,因为这些是响应命令的。假设您可以控制平台,请选择支持信息亭模式的窗口管理器。然后使用窗口管理器的设置启动您的应用程序并进入自助服务终端模式。

There's no point in trying to do this in your application because any of these changes are going to need to be handled by X11 and/or the window manager since those are what respond to the commands. Assuming that you have control of the platform, choose a window manager which supports a kiosk mode. Then use the window manager's settings to start your application and enter kiosk mode.

可以执行此操作的窗口管理器选项包括 KDE twm-kiosk

Options for window managers which can do this include KDE or twm-kiosk.

(如果您无法控制平台,那么您就是不太可能让你的应用程序拦截像ctrl-alt-backspace这样的东西。)

(And if you don't have control of the platform, you're not likely to be able to have your application intercept things like ctrl-alt-backspace anyway.)

编辑:

为了回答问题的缩小版本,他愿意让像ctl-alt-backspace这样的东西去,只是想要大多数键,包括alt-tab或其他类似的应用程序切换键组合,以下内容应该可行:

In response to a scaled-down version of the question in which he's willing to let things like ctl-alt-backspace go and just wants most of the keys including alt-tab or other similar application switching key combinations, the following should work:

您应该可以使用XLib的 XG通过JNI的rabKeyboard 方法。这个 Java / XLib JNI按键捕获教程应该是一个很好的起点。但是,它使用XGrabKey,它只是被动地侦听密钥,并不会阻止其他应用程序接收它们。你会想要使用XGrabKeyboard来主动阻止所有正常的键盘事件(如果这个 StackOverflow问题是正确的,包括任务切换键。)

You should be able to do this using XLib's XGrabKeyboard method through JNI. This Java/XLib JNI keypress capture tutorial should be a good starting point. However, it uses XGrabKey which just passively listens for keys and does not prevent other applications from receiving them. You'll instead want to use XGrabKeyboard which actively snags all of the normal keyboard events (which, if the premise of this StackOverflow question is correct, includes the task switching keys).

请注意,作为副作用,Swing中的键捕获也可能会停止因为您的Swing窗口将与您在C中创建的窗口分开,因此,您可能必须使用JNI接口在需要时按键到您的程序。 (虽然我肯定会建议在编写代码之前先测试它。)如果你可以使用 Java AWT Native Interface 获取窗口ID。 (注意,Swing是建立在AWT之上的,所以这适用于Swing。)但是,我不知道如何做到这一点。看起来你可以通过从显示器获取根窗口并从那里找到你的窗口来导航窗口树,但这有点奇怪。如果AWT NI只是告诉你窗口ID会很好,但它看起来不像那样。

Note that as a side-effect, key capture in Swing will also probably stop working because your Swing windows are going to be separate from the window you create in C. As such, you will probably have to use your JNI interface to get key presses to your program when needed. (Although I would definitely advise testing it first before writing the code.) You might be able to avoid this if you can get the window using Java AWT Native Interface to get the window ID. (Note that Swing is built on top of AWT, so this will work for Swing.) However, I'm not sure how to do this. It looks like you might be able to navigate the window tree by getting the root window from the Display and going from there to find your Window, but it's all kind of weird. It would be nice if the AWT NI just told you the window ID, but it doesn't look like it does that.

这个警告提醒:XGrabKeyboard不是安全界面说明,这不是它其他程序无法看到密钥,但是窗口管理器似乎不会使用XQueryKeyMap,因此可能会阻止任务切换。

As this warning Reminder: XGrabKeyboard is not a security interface notes, this doesn't make it impossible for other programs to see the keys, but it seems likely that window managers will not be using XQueryKeyMap so it is likely to prevent task switching.

这篇关于适用于Linux Java Swing应用程序的Kiosk模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆