本文整理匯總了Java中org.jnativehook.keyboard.NativeKeyEvent.META_MASK屬性的典型用法代碼示例。如果您正苦於以下問題:Java NativeKeyEvent.META_MASK屬性的具體用法?Java NativeKeyEvent.META_MASK怎麽用?Java NativeKeyEvent.META_MASK使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.jnativehook.keyboard.NativeKeyEvent
的用法示例。
在下文中一共展示了NativeKeyEvent.META_MASK屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: nativeKeyPressed
public void nativeKeyPressed(NativeKeyEvent e) {
boolean isMetaPressed = (e.getModifiers() & NativeKeyEvent.META_MASK) > 0;
boolean isAltPressed = (e.getModifiers() & NativeKeyEvent.ALT_MASK) > 0;
boolean isShiftPressed = (e.getModifiers() & NativeKeyEvent.SHIFT_MASK) > 0;
boolean isCtrlPressed = (e.getModifiers() & NativeKeyEvent.CTRL_MASK) > 0;
if(isWindows()){
// ALT+SHIFT+2
if (e.getKeyCode() == NativeKeyEvent.VK_2 && isShiftPressed && isAltPressed){
logger.trace("ALT+SHIFT+2 is pressed");
startRecording();
}
// ALTL+SHIFT+ESC
if (e.getKeyCode() == NativeKeyEvent.VK_ESCAPE && isShiftPressed && isAltPressed){
logger.trace("ALT+SHIFT+ESC is pressed");
GlobalScreen.unregisterNativeHook();
escapeSignal.countDown();
}
}
else{
// CTRL+SHIFT+2
if (e.getKeyCode() == NativeKeyEvent.VK_2 && isShiftPressed && isCtrlPressed){
logger.trace("CTRL+SHIFT+2 is pressed");
startRecording();
}
// CTRL+SHIFT+ESC
if (e.getKeyCode() == NativeKeyEvent.VK_ESCAPE && isShiftPressed && isCtrlPressed){
logger.trace("CTRL+SHIFT+ESC is pressed");
GlobalScreen.unregisterNativeHook();
escapeSignal.countDown();
}
}
}
示例2: nativeKeyPressed
@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;
}
}
示例3: isMetaPressed
boolean isMetaPressed(NativeKeyEvent e){
return (e.getModifiers() & NativeKeyEvent.META_MASK) > 0;
}