本文整理匯總了Java中org.jnativehook.keyboard.NativeKeyEvent.getRawCode方法的典型用法代碼示例。如果您正苦於以下問題:Java NativeKeyEvent.getRawCode方法的具體用法?Java NativeKeyEvent.getRawCode怎麽用?Java NativeKeyEvent.getRawCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jnativehook.keyboard.NativeKeyEvent
的用法示例。
在下文中一共展示了NativeKeyEvent.getRawCode方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: keyConverter
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
public int keyConverter(NativeKeyEvent event) {
if (event.getRawCode() == 56) {
return KeyWrapper.keyToCode("SHIFT");
} else if (event.getRawCode() == 59) {
return KeyWrapper.keyToCode("CONTROL");
} else if (event.getRawCode() == 55) {
return KeyWrapper.keyToCode("META");
} else if (event.getRawCode() == 58) {
return KeyWrapper.keyToCode("ALT");
} else {
return event.getKeyCode();
}
}
示例2: KeyPair
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
KeyPair(NativeKeyEvent e){
keyCode = e.getKeyCode(); rawCode = e.getRawCode();
}
示例3: nativeKeyPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public void nativeKeyPressed(NativeKeyEvent e) {
if (hotkeyIsPressed) {
return; // Do nothing if Hotkey is already pressed.
}
int modifiers = e.getModifiers();
if (modifiers == 0)
return; // Do nothing when no modifiers are pressed, because it's not a hotkey.
boolean isAltPressed = (modifiers & NativeKeyEvent.ALT_MASK) != 0;
boolean isShiftPressed = (modifiers & NativeKeyEvent.SHIFT_MASK) != 0;
// Shortcut modifier is Control modifier in Windows/Linux system and Meta (Command) in
// Mac systems.
boolean isShortcutPressed = (modifiers & NativeKeyEvent.CTRL_MASK)
+ (modifiers & NativeKeyEvent.META_MASK) != 0;
for (Entry<Hotkey, ObjectProperty<KeyCodeCombination>> entry : registeredHotkeys
.entrySet()) {
KeyCodeCombination kcc = entry.getValue().get();
if (kcc == null)
continue; // Do nothing if KeyCodeCombination is not set for this Hotkey.
// FIXME: provide compatibility with Java 9 (pretty easy).
if (e.getRawCode() != kcc.getCode().impl_getCode())
continue; // Key code does not match Hotkey.
if (isAltPressed != (kcc.getAlt() == ModifierValue.DOWN))
continue; // Alt modifier doesn't match Hotkey.
if (isShiftPressed != (kcc.getShift() == ModifierValue.DOWN))
continue; // Shift modifier doesn't match Hotkey.
if (isShortcutPressed != (kcc.getShortcut() == ModifierValue.DOWN))
continue; // Shortcut modifier doesn't match Hotkey.
if (hotkeyIsRunning) {
logger.error("Previously pressed Hotkey is still running.");
return; // Do nothing if Hotkey is still running.
}
// At this point the pressed key and modifiers match one of the registered Hotkeys.
// Let's run the associated runnable with this Hotkey.
Hotkey hotkey = entry.getKey();
logger.info("Catched the Hotkey: \"" + hotkey.name()
+ "\". Running the associated action.");
hotkeyIsPressed = true;
hotkeyIsRunning = true;
Runnable task = () -> {
hotkey.run();
logger.info("Finished running the action associated with the Hotkey: \""
+ hotkey.name() + "\".");
hotkeyIsRunning = false;
};
new Thread(task).start();
break;
}
}