是否可以使用 Java (Swing) 锁定 Windows OS 桌面?
Is it possible to lock the Windows OS desktop using Java (Swing)?
我正在尝试制作一个类似于网吧软件的小应用程序。
具体来说,我想做的是一旦应用启动,你就不能在电脑上做任何事情,也不可能解除锁定,(Alt + F4, Ctrl + Alt + Del,任务管理器等),除非你设置了特定的用户名和密码,一旦过了特定的时间,软件就会再次锁定计算机。
我几乎是 Java 的新手,所以我找不到任何我能理解的答案,也找不到我正在寻找的答案。这可能吗?
提前致谢!
您可能需要使用 JNA 来执行类似的操作,或者只需更改为 C++/C#。
例如这样的例子:
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HMODULE;
import com.sun.jna.platform.win32.WinDef.LRESULT;
import com.sun.jna.platform.win32.WinDef.WPARAM;
import com.sun.jna.platform.win32.WinUser.HHOOK;
import com.sun.jna.platform.win32.WinUser.KBDLLHOOKSTRUCT;
import com.sun.jna.platform.win32.WinUser.LowLevelKeyboardProc;
import com.sun.jna.platform.win32.WinUser.MSG;
public class KeyHook {
private static HHOOK hhk;
private static LowLevelKeyboardProc keyboardHook;
private static User32 lib;
public static void blockWindowsKey() {
if (isWindows()) {
new Thread(new Runnable() {
@Override
public void run() {
lib = User32.INSTANCE;
HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);
keyboardHook = new LowLevelKeyboardProc() {
public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT info) {
if (nCode >= 0) {
switch (info.vkCode){
case 0x5B: //Around here would be where you add all your 0x key codes
case 0x5C:
return new LRESULT(1);
default: //do nothing
}
}
return lib.CallNextHookEx(hhk, nCode, wParam, info.getPointer());
}
};
hhk = lib.SetWindowsHookEx(13, keyboardHook, hMod, 0);
// This bit never returns from GetMessage
int result;
MSG msg = new MSG();
while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) {
if (result == -1) {
break;
} else {
lib.TranslateMessage(msg);
lib.DispatchMessage(msg);
}
}
lib.UnhookWindowsHookEx(hhk);
}
}).start();
}
}
public static void unblockWindowsKey() {
if (isWindows() && lib != null) {
lib.UnhookWindowsHookEx(hhk);
}
}
public static boolean isWindows(){
String os = System.getProperty("os.name").toLowerCase();
return (os.indexOf( "win" ) >= 0);
}
}
(那不是我的,待会儿再解释)
然后看看是不是运行 Windows by 'KeyHook.isWindows()'.
如果是,请使用 'blockWindowsKey()' 之类的东西或制作您自己的函数。我在您要更改密钥代码的地方添加了评论。
仅供参考 is it is possible to disable the windows keys using java 可能重复
这就是代码的来源。
我正在尝试制作一个类似于网吧软件的小应用程序。
具体来说,我想做的是一旦应用启动,你就不能在电脑上做任何事情,也不可能解除锁定,(Alt + F4, Ctrl + Alt + Del,任务管理器等),除非你设置了特定的用户名和密码,一旦过了特定的时间,软件就会再次锁定计算机。
我几乎是 Java 的新手,所以我找不到任何我能理解的答案,也找不到我正在寻找的答案。这可能吗?
提前致谢!
您可能需要使用 JNA 来执行类似的操作,或者只需更改为 C++/C#。
例如这样的例子:
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HMODULE;
import com.sun.jna.platform.win32.WinDef.LRESULT;
import com.sun.jna.platform.win32.WinDef.WPARAM;
import com.sun.jna.platform.win32.WinUser.HHOOK;
import com.sun.jna.platform.win32.WinUser.KBDLLHOOKSTRUCT;
import com.sun.jna.platform.win32.WinUser.LowLevelKeyboardProc;
import com.sun.jna.platform.win32.WinUser.MSG;
public class KeyHook {
private static HHOOK hhk;
private static LowLevelKeyboardProc keyboardHook;
private static User32 lib;
public static void blockWindowsKey() {
if (isWindows()) {
new Thread(new Runnable() {
@Override
public void run() {
lib = User32.INSTANCE;
HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);
keyboardHook = new LowLevelKeyboardProc() {
public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT info) {
if (nCode >= 0) {
switch (info.vkCode){
case 0x5B: //Around here would be where you add all your 0x key codes
case 0x5C:
return new LRESULT(1);
default: //do nothing
}
}
return lib.CallNextHookEx(hhk, nCode, wParam, info.getPointer());
}
};
hhk = lib.SetWindowsHookEx(13, keyboardHook, hMod, 0);
// This bit never returns from GetMessage
int result;
MSG msg = new MSG();
while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) {
if (result == -1) {
break;
} else {
lib.TranslateMessage(msg);
lib.DispatchMessage(msg);
}
}
lib.UnhookWindowsHookEx(hhk);
}
}).start();
}
}
public static void unblockWindowsKey() {
if (isWindows() && lib != null) {
lib.UnhookWindowsHookEx(hhk);
}
}
public static boolean isWindows(){
String os = System.getProperty("os.name").toLowerCase();
return (os.indexOf( "win" ) >= 0);
}
}
(那不是我的,待会儿再解释) 然后看看是不是运行 Windows by 'KeyHook.isWindows()'.
如果是,请使用 'blockWindowsKey()' 之类的东西或制作您自己的函数。我在您要更改密钥代码的地方添加了评论。
仅供参考 is it is possible to disable the windows keys using java 可能重复 这就是代码的来源。