Robot Java class XP and Vista win7
•
Java
The following java code will lock the desktop when running on Windows XP, but it will not lock the desktop when running on Vista or windows 7 I would appreciate it if someone could tell me how to use it in Vista and windows 7 using java only
import java.awt.AWTException; import java.awt.Robot; import java.awt.event.KeyEvent; public class Roboto { //Lock windows desktop using "WinKey + L" public static void main(String[] args) { try { Robot r = new Robot(); r.keyPress(KeyEvent.VK_WINDOWS); r.keyPress(KeyEvent.VK_L); r.keyRelease(KeyEvent.VK_L); r.keyRelease(KeyEvent.VK_WINDOWS); } catch (AWTException e) { e.printStackTrace(); } } }
Solution
It sounds like Vista's UAC prevents the JVM from sending events to the OS event queue Since you didn't mention it, I don't think you saw anything unusual Can you try running with administrator privileges?
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码