本文整理匯總了Java中org.jnativehook.keyboard.NativeKeyEvent.getModifiers方法的典型用法代碼示例。如果您正苦於以下問題:Java NativeKeyEvent.getModifiers方法的具體用法?Java NativeKeyEvent.getModifiers怎麽用?Java NativeKeyEvent.getModifiers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jnativehook.keyboard.NativeKeyEvent
的用法示例。
在下文中一共展示了NativeKeyEvent.getModifiers方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: nativeKeyTyped
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
@Override
public void nativeKeyTyped(NativeKeyEvent e)
{
if (hotkeyMap.isEmpty() && !isKeySelection) //not for us
return;
int modifiers = e.getModifiers();
HotkeyConfiguration hotkeyConfig;
if (isKeySelection)
{
hotkeyConfig = hotkeyMap.get(hotkeySelectionID);
}
else
{
String hotkeyAsStr = hotkeyToString(modifiers, lastKeycode);
String hotkeyID = hotkeyToID.get(hotkeyAsStr);
hotkeyConfig = hotkeyMap.get(hotkeyID);
if (hotkeyConfig == null) //not a hotkey
return;
}
hotkeyConfig.getExecutor().keyPressed(modifiers, lastKeycode, isKeySelection);
isKeySelection = false;
}
示例2: nativeKeyPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
@Override
public void nativeKeyPressed(NativeKeyEvent event) {
if (mActiveKeys.containsKey(event.getRawCode())) {
return;
}
BioKeystrokeEvent bioEvent = new BioKeystrokeEvent();
bioEvent.press_time = event.getWhen();
bioEvent.key_code = event.getKeyCode();
bioEvent.key_string = NativeKeyEvent.getKeyText(event.getKeyCode()).toLowerCase().replace(' ', '_');
bioEvent.modifier_code = event.getModifiers();
bioEvent.modifier_name = NativeKeyEvent.getModifiersText(event.getModifiers()).toLowerCase().replace(' ', '_');
bioEvent.key_location = event.getKeyLocation();
mActiveKeys.put(event.getRawCode(), bioEvent);
BioLogger.LOGGER.info("Key pressed:: key code: " + bioEvent.key_code + ", key name: " + bioEvent.key_string);
}
示例3: evaluateKeyEvent
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
private boolean evaluateKeyEvent(NativeKeyEvent event, char key) {
String keyText = NativeKeyEvent.getKeyText(event.getKeyCode());
keyText = keyText.equals("Space") ? " " : keyText;
Character pressed = keyText.length() == 1 ? keyText.charAt(0) : null;
return event.getModifiers() == NativeKeyEvent.CTRL_MASK
&& pressed != null && pressed == key;
}
示例4: nativeKeyPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
@Override
public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) {
pressed.addKey(new Key((char) nativeKeyEvent.getKeyCode()));
System.out.println(nativeKeyEvent.paramString());
System.out.println(nativeKeyEvent.getKeyChar());
System.out.println("modifier: " + nativeKeyEvent.getModifiers());
if((nativeKeyEvent.getModifiers() & NativeKeyEvent.CTRL_L_MASK) != 0) {
System.out.println("ctrl!");
}
System.out.println(String.format("pressed num: %d", pressed.getKeys().size()));
}
示例5: nativeKeyPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
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();
}
}
}
示例6: nativeKeyPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
public void nativeKeyPressed(NativeKeyEvent e) {
if (e.getKeyCode() == NativeKeyEvent.VC_PRINTSCREEN
&& ((e.getModifiers() & NativeKeyEvent.SHIFT_L_MASK) == NativeKeyEvent.SHIFT_L_MASK ||
(e.getModifiers() & NativeKeyEvent.SHIFT_R_MASK) == NativeKeyEvent.SHIFT_R_MASK
)) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
screenSelectorShell.setPanel(new VideoCaptureTool(processor));
screenSelectorShell.open();
}
});
} else if (e.getKeyCode() == NativeKeyEvent.VC_PRINTSCREEN) {
if ((e.getModifiers() & NativeKeyEvent.CTRL_L_MASK) == NativeKeyEvent.CTRL_L_MASK ||
(e.getModifiers() & NativeKeyEvent.CTRL_R_MASK) == NativeKeyEvent.CTRL_R_MASK
) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
ImageCaptureTool imageCaptureTool = new ImageCaptureTool(config, iconManager, processor);
imageCaptureTool.open(Display.getDefault().getBounds());
}
});
return;
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
screenSelectorShell.setPanel(new ImageCaptureTool(config, iconManager, processor));
screenSelectorShell.open();
}
});
}
if (e.getKeyCode() == NativeKeyEvent.VC_ESCAPE) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
screenSelectorShell.close();
}
});
}
}
示例7: 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;
}
}
示例8: isConsoleToggleEvent
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
private boolean isConsoleToggleEvent(NativeKeyEvent evt) {
return evt.getKeyCode() == NativeKeyEvent.VC_BACKQUOTE && (evt.getModifiers() == NativeKeyEvent.CTRL_L_MASK);
}
示例9: isMetaPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
boolean isMetaPressed(NativeKeyEvent e){
return (e.getModifiers() & NativeKeyEvent.META_MASK) > 0;
}
示例10: isAltPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
boolean isAltPressed(NativeKeyEvent e){
return (e.getModifiers() & NativeKeyEvent.ALT_MASK) > 0;
}
示例11: isShiftPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
boolean isShiftPressed(NativeKeyEvent e){
return (e.getModifiers() & NativeKeyEvent.SHIFT_MASK) > 0;
}
示例12: isCtrlPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
boolean isCtrlPressed(NativeKeyEvent e){
return (e.getModifiers() & NativeKeyEvent.CTRL_MASK) > 0;
}
示例13: isCrtlShiftOnMac
import org.jnativehook.keyboard.NativeKeyEvent; //導入方法依賴的package包/類
/**
* OSX has different Modifiers value for Shift+Ctrl than Windows/Linux.
*
* @param event
* @return true if Shift+Ctrl was pressed
*/
private boolean isCrtlShiftOnMac(NativeKeyEvent event) {
return OSUtils.isOnMac() && event.getModifiers() == MAC_SHIFT_CTRL_MODIFIER;
}