int vk = KeyEvent.VK_D;
int id = 1;
assertTrue("RegisterHotKey failed", INSTANCE.RegisterHotKey(null, id, WinUser.MOD_CONTROL | WinUser.MOD_ALT, vk));
Robot robot = null;
try {
robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(vk);
Thread.sleep(50);
robot.keyRelease(vk);
WinUser.MSG msg = waitForMessage(500);
assertNotNull(msg);
assertEquals(msg.wParam.intValue(), id);
assertTrue(INSTANCE.UnregisterHotKey(null, id));
robot.keyPress(vk);
Thread.sleep(10);
robot.keyRelease(vk);
msg = waitForMessage(500);
assertNull(msg);
} catch (AWTException e) {
e.printStackTrace();
fail();
} catch (InterruptedException e) {
e.printStackTrace();
fail();
} finally {
if (robot != null) {
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_ALT);
}
}
}