org.jnativehook.keyboard.NativeKeyEvent Java Examples

The following examples show how to use org.jnativehook.keyboard.NativeKeyEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JNativeKeyHandler.java    From Spark-Reader with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent)
{
    //FIXME this is a temporary implementation
    //TODO use some user defined lookup table for key mappings
    //System.out.println("Key pressed: " + nativeKeyEvent.getKeyCode());
    //this seems to do key repeats as well. Convenient
    switch(nativeKeyEvent.getKeyCode())
    {
        case 30://a
            keyAction(KeyEvent.simMouseScrollUp);
            break;
        case 44://z
            keyAction(KeyEvent.simMouseScrollDown);
            break;
        case 45://x
            keyAction(KeyEvent.simMouseMiddle);
            break;
        case NativeKeyEvent.VC_ESCAPE:
            keyAction(KeyEvent.hideWindow);
            break;
        case NativeKeyEvent.VC_ENTER:
            keyAction(KeyEvent.advanceText);
    }
}
 
Example #2
Source File: MercuryNativeKeyListener.java    From MercuryTrade with MIT License 6 votes vote down vote up
@Override
public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) {
    switch (nativeKeyEvent.getKeyCode()) {
        case 42: {
            shiftPressed = true;
            break;
        }
        case 29: {
            ctrlpressed = true;
            break;
        }
        case 56: {
            menuPressed = true;
            break;
        }
        default: {
            if (!this.block) {
                MercuryStoreCore.hotKeySubject.onNext(this.getDescriptor(nativeKeyEvent));
            }
        }
    }
}
 
Example #3
Source File: GlobalShortcutListener.java    From nanoleaf-desktop with MIT License 5 votes vote down vote up
@Override
public void nativeKeyReleased(NativeKeyEvent e)
{
	String key = NativeKeyEvent.getKeyText(e.getKeyCode());
	if (pressedKeys.contains(key))
	{
		pressedKeys.remove(key);
	}
	checkKeyShortcuts(1);
}
 
Example #4
Source File: GlobalKeyListener.java    From foolqq with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void nativeKeyPressed(NativeKeyEvent e) {

		if (e.getKeyCode() == NativeKeyEvent.VC_ESCAPE) {
			try {
				GlobalScreen.unregisterNativeHook();
				System.exit(1);
			} catch (NativeHookException e1) {

			}
		}
	}
 
Example #5
Source File: GlobalKeyListener.java    From pmTrans with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: GlobalKeyListener.java    From pmTrans with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void nativeKeyReleased(final NativeKeyEvent event) {
	if (evidenceBucket != null)
		if (evaluateKeyEvent(event,
				Config.getInstance().getString(Config.PAUSE_KEY)
						.toLowerCase().charAt(0)))
			evidenceBucket.pauseAndRewind();
		else if (evaluateKeyEvent(event,
				Config.getInstance().getString(Config.SHORT_REWIND_KEY)
						.toLowerCase().charAt(0)))
			evidenceBucket.rewind(Config.getInstance().getInt(
					Config.SHORT_REWIND));
		else if (evaluateKeyEvent(event,
				Config.getInstance().getString(Config.LONG_REWIND_KEY)
						.toLowerCase().charAt(0)))
			evidenceBucket.rewind(Config.getInstance().getInt(
					Config.LONG_REWIND));
		else if (evaluateKeyEvent(event,
				Config.getInstance().getString(Config.SPEED_UP_KEY)
						.toLowerCase().charAt(0)))
			evidenceBucket.modifyAudioPlaybackRate(Config.getInstance()
					.getInt(Config.SPEED_UP_PLAYBACK));
		else if (evaluateKeyEvent(event,
				Config.getInstance().getString(Config.SLOW_DOWN_KEY)
						.toLowerCase().charAt(0)))
			evidenceBucket.modifyAudioPlaybackRate(Config.getInstance()
					.getInt(Config.SLOW_DOWN_PLAYBACK));
		else if (evaluateKeyEvent(event,
				Config.getInstance().getString(Config.AUDIO_LOOPS_KEY)
						.toLowerCase().charAt(0)))
			evidenceBucket.selectAudioLoops();
}
 
Example #7
Source File: KeyLogger.java    From BetterBackdoor with MIT License 5 votes vote down vote up
@Override
public void nativeKeyPressed(NativeKeyEvent key) {
	String pressed = NativeKeyEvent.getKeyText(key.getKeyCode());

	if (pressed.equals("Shift"))
		shift = true;

	if (key.isActionKey())
		out.print("[" + pressed + "]");
	else if (pressed.equals("Backspace"))
		out.print("[Back]");
	else if (pressed.equals("Space"))
		out.print(" ");
	else if (pressed.equals("Tab"))
		out.print("\t");
	else if (pressed.equals("Enter"))
		out.println();
	else if (shift) {
		if (pressed.matches("[A-Z]"))
			out.print(pressed);
		else if (pressed.equals("1"))
			out.print("!");
		else if (pressed.equals("2"))
			out.print("@");
		else if (pressed.equals("3"))
			out.print("#");
		else if (pressed.equals("4"))
			out.print("$");
		else if (pressed.equals("5"))
			out.print("%");
		else if (pressed.equals("6"))
			out.print("^");
		else if (pressed.equals("7"))
			out.print("&");
		else if (pressed.equals("8"))
			out.print("*");
		else if (pressed.equals("9"))
			out.print("(");
		else if (pressed.equals("0"))
			out.print(")");
		else if (pressed.equals("Minus"))
			out.print("_");
		else if (pressed.equals("Equals"))
			out.print("+");
		else if (pressed.equals("Open Bracket"))
			out.print("{");
		else if (pressed.equals("Close Bracket"))
			out.print("}");
		else if (pressed.equals("Back Slash"))
			out.print("|");
		else if (pressed.equals("Semicolon"))
			out.print(":");
		else if (pressed.equals("Quote"))
			out.print("\"");
		else if (pressed.equals("Comma"))
			out.print("<");
		else if (pressed.equals("Period"))
			out.print(">");
		else if (pressed.equals("Dead Acute"))
			out.print("?");
		else if (pressed.equals("Back Quote"))
			out.print("~");
	} else {
		if (pressed.matches("[a-zA-Z0-9]"))
			out.print(pressed.toLowerCase());
		else if (pressed.equals("Minus"))
			out.print("-");
		else if (pressed.equals("Equals"))
			out.print("=");
		else if (pressed.equals("Open Bracket"))
			out.print("[");
		else if (pressed.equals("Close Bracket"))
			out.print("]");
		else if (pressed.equals("Back Slash"))
			out.print("\\");
		else if (pressed.equals("Semicolon"))
			out.print(";");
		else if (pressed.equals("Quote"))
			out.print("'");
		else if (pressed.equals("Comma"))
			out.print(",");
		else if (pressed.equals("Period"))
			out.print(".");
		else if (pressed.equals("Dead Acute"))
			out.print("/");
		else if (pressed.equals("Back Quote"))
			out.print("`");
	}
	out.flush();
}
 
Example #8
Source File: KeyboardEventNotificator.java    From DeskChan with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Key pressed event (called every tick you press the button, not once). **/
public void nativeKeyPressed(NativeKeyEvent e) {
    //System.out.print("pressed " + currentPressed);
    synchronized (this) {
        if (currentPressed.add(new KeyPair(e)) && commands != null && commands.length > 0) {
            setChanged = true;
            handler.start();
            if (listenerId >= 0) {
                updateKeysInSubMenu();
            }
        }
    }
    //System.out.println("exited");
}
 
Example #9
Source File: KeyboardEventNotificator.java    From DeskChan with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** Key released event. **/
public void nativeKeyReleased(NativeKeyEvent e) {
    synchronized (this) {
        currentPressed.remove(new KeyPair(e));
        setChanged = true;
        if (currentPressed.size() == 0)
            handler.stop();
        if (listenerId >= 0) {
            updateKeysInSubMenu();
        }
    }
}
 
Example #10
Source File: RecordedEventsFlow.java    From SikuliX1 with MIT License 5 votes vote down vote up
private Long findNextPressedKeyEventTime(Long time) {
  Map<Long, NativeInputEvent> nextEvents = events.subMap(time + 1, time + 3000);

  for(Map.Entry<Long, NativeInputEvent> entry : nextEvents.entrySet()) {
    NativeInputEvent event = entry.getValue();

    if(event instanceof NativeKeyEvent) {
      if(NativeKeyEvent.NATIVE_KEY_PRESSED == entry.getValue().getID()) {
        return entry.getKey();
      }
    } else {
      return null;
    }
  }

  return null;
}
 
Example #11
Source File: RecordedEventsFlow.java    From SikuliX1 with MIT License 5 votes vote down vote up
/**
 * Transforms the added events and screenshots
 * to a successive list of actions.
 *
 * @param progress optional progress monitor
 * @return A list of performed actions
 */
public List<IRecordedAction> compile(ProgressMonitor progress) {
  synchronized (this) {
    if (progress != null) {
      progress.setMinimum(0);
      progress.setMaximum(events.size());
    }

    List<org.sikuli.script.support.recorder.actions.IRecordedAction> actions = new LinkedList<>();
    modifiers.clear();
    typedText = new StringBuilder();

    int i = 0;

    for (Map.Entry<Long, NativeInputEvent> entry : events.entrySet()) {
      if (progress != null && progress.isCanceled()) {
        return new LinkedList<>();
      }

      Long time = entry.getKey();
      NativeInputEvent event = entry.getValue();

      if (event instanceof NativeKeyEvent) {
        actions.addAll(handleKeyEvent(time, (NativeKeyEvent) event));
      } else if (event instanceof NativeMouseEvent) {
        actions.addAll(handleMouseEvent(time, (NativeMouseEvent) event));
      }

      if (progress != null) {
        progress.setProgress(++i);
      }
    }

    if (!actions.isEmpty()) {
      actions.remove(actions.size() - 1);
    }

    return actions;
  }
}
 
Example #12
Source File: GlobalJNativeHookKeyListener.java    From Repeat with Apache License 2.0 5 votes vote down vote up
@Override
public void nativeKeyPressed(NativeKeyEvent e) {
	int code = e.getKeyCode();
	long time = System.currentTimeMillis();

	if (keyPressed != null) {
		if ((!m.containsKey(code)) || (m.get(code) - time >= KEY_PRESS_DELAY_MS)) {
			KeyStroke stroke = JNativeHookCodeConverter.getKeyEventCode(code).press(true).at(LocalDateTime.now());
			if (!keyPressed.apply(stroke.toNativeKeyEvent())) {
				LOGGER.warning("Internal key listener problem. Unable to apply key pressed action");
			}
		}
	}
	m.put(code, time);
}
 
Example #13
Source File: GlobalShortcutListener.java    From nanoleaf-desktop with MIT License 5 votes vote down vote up
@Override
public void nativeKeyPressed(NativeKeyEvent e)
{
	String key = NativeKeyEvent.getKeyText(e.getKeyCode());
	if (!pressedKeys.contains(key))
	{
		pressedKeys.add(key);
	}
	checkKeyShortcuts(0);
}
 
Example #14
Source File: GlobalJNativeHookKeyListener.java    From Repeat with Apache License 2.0 5 votes vote down vote up
@Override
public void nativeKeyReleased(NativeKeyEvent e) {
	m.remove(e.getKeyCode());

	if (keyReleased != null) {
		KeyStroke stroke = JNativeHookCodeConverter.getKeyEventCode(e.getKeyCode()).press(false).at(LocalDateTime.now());

		if (!keyReleased.apply(stroke.toNativeKeyEvent())) {
			LOGGER.warning("Internal key listener problem. Unable to apply key released action");
		}
	}
}
 
Example #15
Source File: GlobalKeyListener.java    From Path-of-Leveling with MIT License 5 votes vote down vote up
@Override
public void nativeKeyPressed(NativeKeyEvent e) {
	//System.out.println("Key Pressed: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
               mapper.add(e.getKeyCode());
               String input = "Key Pressed: ";
               for(Integer a : mapper){
                   input+= "+ " + NativeKeyEvent.getKeyText(a);
               }
               //System.out.println(input);
               handle();
}
 
Example #16
Source File: MercuryNativeKeyListener.java    From MercuryTrade with MIT License 5 votes vote down vote up
@Override
public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent) {
    if (!this.block) {
        MercuryStoreCore.hotKeyReleaseSubject.onNext(this.getDescriptor(nativeKeyEvent));
    }
    switch (nativeKeyEvent.getKeyCode()) {
        case 42: {
            shiftPressed = false;
            break;
        }
        case 29: {
            ctrlpressed = false;
            break;
        }
        case 56: {
            menuPressed = false;
            break;
        }
    }
}
 
Example #17
Source File: GlobalKeyListener.java    From tools-ocr with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void preventEvent(NativeKeyEvent e){
    try {
        Field f = NativeInputEvent.class.getDeclaredField("reserved");
        f.setAccessible(true);
        f.setShort(e, (short) 0x01);
    }
    catch (Exception ex) {
        StaticLog.error(ex);
    }
}
 
Example #18
Source File: MercuryNativeKeyListener.java    From MercuryTrade with MIT License 5 votes vote down vote up
private HotKeyDescriptor getDescriptor(NativeKeyEvent nativeKeyEvent) {
    HotKeyDescriptor hotKeyDescriptor = new HotKeyDescriptor();
    hotKeyDescriptor.setTitle(NativeKeyEvent.getKeyText(nativeKeyEvent.getKeyCode()));
    hotKeyDescriptor.setVirtualKeyCode(nativeKeyEvent.getKeyCode());
    hotKeyDescriptor.setControlPressed(ctrlpressed);
    hotKeyDescriptor.setShiftPressed(shiftPressed);
    hotKeyDescriptor.setMenuPressed(menuPressed);

    hotKeyDescriptor.setTitle(this.getButtonText(hotKeyDescriptor));
    return hotKeyDescriptor;
}
 
Example #19
Source File: GlobalKeyListener.java    From tools-ocr with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void nativeKeyPressed(NativeKeyEvent e) {
    if (e.getKeyCode() == NativeKeyEvent.VC_F4){
        preventEvent(e);
        MainFm.doSnap();
    }
    else if (e.getKeyCode() == NativeKeyEvent.VC_ESCAPE){
        if (ScreenCapture.isSnapping){
            preventEvent(e);
            MainFm.cancelSnap();
        }
    }
}
 
Example #20
Source File: Keylogger.java    From sAINT with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void nativeKeyTyped(NativeKeyEvent nke) {
    SaveLogs(String.valueOf(nke.getKeyChar()));
}
 
Example #21
Source File: GlobalJNativeHookKeyListener.java    From Repeat with Apache License 2.0 4 votes vote down vote up
@Override
public final void nativeKeyTyped(NativeKeyEvent arg0) {
}
 
Example #22
Source File: KeyboardEventNotificator.java    From DeskChan with GNU Lesser General Public License v3.0 4 votes vote down vote up
/** It does nothing but needs to me implemented. **/
public void nativeKeyTyped(NativeKeyEvent e) { }
 
Example #23
Source File: MercuryNativeKeyListener.java    From MercuryTrade with MIT License 4 votes vote down vote up
@Override
public void nativeKeyTyped(NativeKeyEvent nativeKeyEvent) {
}
 
Example #24
Source File: KeyboardEventNotificator.java    From DeskChan with GNU Lesser General Public License v3.0 4 votes vote down vote up
KeyPair(NativeKeyEvent e){
    keyCode = e.getKeyCode(); rawCode = e.getRawCode();
}
 
Example #25
Source File: GlobalKeyListener.java    From foolqq with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void nativeKeyTyped(NativeKeyEvent e) {
}
 
Example #26
Source File: GlobalKeyListener.java    From foolqq with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void nativeKeyReleased(NativeKeyEvent e) {
}
 
Example #27
Source File: JNativeKeyHandler.java    From Spark-Reader with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void nativeKeyTyped(NativeKeyEvent nativeKeyEvent)
{
    //this never fires due to some keyboard locale issue, at least on my machine
}
 
Example #28
Source File: JNativeKeyHandler.java    From Spark-Reader with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent)
{

}
 
Example #29
Source File: GlobalKeyListener.java    From pmTrans with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void nativeKeyTyped(NativeKeyEvent arg0) {
	// ignore
}
 
Example #30
Source File: GlobalKeyListener.java    From pmTrans with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void nativeKeyPressed(NativeKeyEvent arg0) {
	// ignore
}