本文整理匯總了Java中org.jnativehook.keyboard.NativeKeyEvent類的典型用法代碼示例。如果您正苦於以下問題:Java NativeKeyEvent類的具體用法?Java NativeKeyEvent怎麽用?Java NativeKeyEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
NativeKeyEvent類屬於org.jnativehook.keyboard包,在下文中一共展示了NativeKeyEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: nativeKeyPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
public void nativeKeyPressed(NativeKeyEvent e) {
int code = e.getKeyCode();
if (code == NativeKeyEvent.VC_CONTROL) {
ctrl = true;
for (int keycode : F_KEYS) {
GlobalKeyConsumer.instance.consumeKeyCode(keycode);
}
} else if (code == NativeKeyEvent.VC_ALT) {
if (e.getKeyLocation() == 3) { // right alt
GlobalKeyConsumer.instance.consumeKeyCode(NativeKeyEvent.VC_C);
ralt = true;
} else if (e.getKeyLocation() == 2) { // left alt
}
}
// log.db(e.getRawCode() + " " + code + " " + e.getKeyLocation() + " " + NativeKeyEvent.ALT_R_MASK);
allReleased = false;
}
示例2: handleLinuxKey
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
private void handleLinuxKey(int rawCode) {
switch (rawCode) {
case 65300:
handleKeyCode(NativeKeyEvent.VC_MEDIA_PLAY);
break;
case 65301:
handleKeyCode(NativeKeyEvent.VC_MEDIA_STOP);
break;
case 65302:
handleKeyCode(NativeKeyEvent.VC_MEDIA_PREVIOUS);
break;
case 65303:
handleKeyCode(NativeKeyEvent.VC_MEDIA_NEXT);
break;
}
}
示例3: handleKeyCode
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
private void handleKeyCode(int keyCode) {
switch (keyCode) {
case NativeKeyEvent.VC_MEDIA_PLAY:
Log.debug("NativeKeyEvent: VC_MEDIA_PLAY");
AudioPlayerThread.togglePause();
break;
case NativeKeyEvent.VC_MEDIA_STOP:
Log.debug("NativeKeyEvent: VC_MEDIA_STOP");
Bot.stopPlayer();
break;
case NativeKeyEvent.VC_MEDIA_PREVIOUS:
Log.debug("NativeKeyEvent: VC_MEDIA_PREVIOUS");
if(AudioPlayerThread.isPlaying()) {
AudioPlayerThread.getMusicManager().player.getPlayingTrack().setPosition(0);
}
break;
case NativeKeyEvent.VC_MEDIA_NEXT:
Log.debug("NativeKeyEvent: VC_MEDIA_NEXT");
AudioPlayerThread.getMusicManager().scheduler.nextTrack(1);
break;
}
}
示例4: nativeKeyPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
/**
* adds hotkey or alpha key to the repespective list if they are in the
* valid list. prevents non valid keys from being added.
*/
@Override
public void nativeKeyPressed(NativeKeyEvent e) {
String temp = NativeKeyEvent.getKeyText(e.getKeyCode());
if (validHotKeys.contains(temp)) {
if (!pressedHotKeys.contains(temp)) {
pressedHotKeys.add(temp);
System.out.println(pressedHotKeys.toString());
}
}
if (validAlphaKeys.contains(temp)) {
if (!pressedAlphaKeys.contains(temp)) {
pressedAlphaKeys.add(temp);
System.out.println(pressedAlphaKeys.toString());
}
}
}
示例5: nativeKeyPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
@Override
public void nativeKeyPressed(NativeKeyEvent e)
{
// TODO Auto-generated method stub
if (mode == 0 && NativeKeyEvent.getKeyText(e.getKeyCode()).matches("W"))
{
if (distanceset)
{
s = new Stopwatch();
mode = 1;
System.out.println("\n1st sensor triggered");
}
else
{
label.setText("Please set the distance.");
}
}
if (mode == 1 && NativeKeyEvent.getKeyText(e.getKeyCode()).matches("A"))
{
time = s.elapsedTime();
mode = 2;
System.out.println("\n2nd sensor triggered");
}
}
示例6: pressMultiKeyTest
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
@Test
public void pressMultiKeyTest() throws AWTException, InterruptedException {
MultiKeyListener mkl = new MultiKeyListener();
GlobalScreen.addNativeKeyListener(mkl);
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_SPACE);
Thread.sleep(300);
Keys pressed = mkl.getPressed();
assertEquals(pressed.getKeys().size(), 2);
assertTrue(pressed.getKeys().contains(new Key((char)NativeKeyEvent.VC_CONTROL_L)));
assertTrue(pressed.getKeys().contains(new Key((char) NativeKeyEvent.VC_SPACE)));
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_SPACE);
assertEquals(pressed.getKeys().size(), 0);
}
示例7: nativeKeyPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
@Override
public void nativeKeyPressed(NativeKeyEvent e) {
String ss = NativeKeyEvent.getKeyText(e.getKeyCode());
if (ss.contains("Shift")) {
shiftState = ButtonStates.ON;
shift = true;
if (shiftChangeListener != null)
shiftChangeListener.stateChanged(shiftState, shift);
} else if (ss.contains("Control")) {
ctrlState = ButtonStates.ON;
ctrl = true;
if (ctrlChangeListener != null)
ctrlChangeListener.stateChanged(ctrlState, ctrl);
} else if (ss.contains("Alt")) {
altState = ButtonStates.ON;
alt = true;
if (altChangeListener != null)
altChangeListener.stateChanged(altState, alt);
}
}
示例8: GlobalKeyListener
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
public GlobalKeyListener() {
m = new HashMap<Integer, Long>();
keyPressed = new Function<NativeKeyEvent, Boolean>() {
@Override
public Boolean apply(NativeKeyEvent r) {
return true;
}
};
keyReleased = new Function<NativeKeyEvent, Boolean>() {
@Override
public Boolean apply(NativeKeyEvent r) {
return true;
}
};
}
示例9: nativeKeyPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
@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));
}
}
}
}
示例10: nativeKeyReleased
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
@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;
}
}
}
示例11: nativeKeyPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
@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);
}
}
示例12: nativeKeyReleased
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
@Override
public void nativeKeyReleased(NativeKeyEvent arg0) {
if ((hash1Ready || hash2Ready)) {
disableListener(callerBtn);
if (callerBtn.equals(btnScreen)) {
Main.config.setScreenKeys(newKey);
} else if (callerBtn.equals(btnCScreen)) {
Main.config.setCScreenKeys(newKey);
} else if (callerBtn.equals(btnFile)) {
Main.config.setFileKeys(newKey);
} else if (callerBtn.equals(btnClipboard)) {
Main.config.setClipboardKeys(newKey);
}
Main.st.updateKeys();
Main.keyListener.loadKeys();
}
}
示例13: nativeKeyPressed
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
@Override
public void nativeKeyPressed(NativeKeyEvent e) {
pressed.add(e.getRawCode());
for (KeyBinding.Type k : KeyBindings.KEYBINDINGS.keySet()) {
KeyBinding kb = KeyBindings.KEYBINDINGS.get(k);
boolean trigger = false;
for (int i : kb.getKeys()) {
if (i != 0) {
if (pressed.contains(i)) {
trigger = true;
} else {
trigger = false;
break;
}
}
}
if (trigger) {
k.trigger();
}
}
}
示例14: addExtraKeys
import org.jnativehook.keyboard.NativeKeyEvent; //導入依賴的package包/類
private void addExtraKeys() {
// Extra keys
extraKeys.add(NativeKeyEvent.VC_DELETE);
extraKeys.add(NativeKeyEvent.VC_INSERT);
extraKeys.add(NativeKeyEvent.VC_HOME);
extraKeys.add(NativeKeyEvent.VC_END);
extraKeys.add(NativeKeyEvent.VC_PAGE_UP);
extraKeys.add(NativeKeyEvent.VC_PAGE_DOWN);
extraKeys.add(NativeKeyEvent.VC_ESCAPE);
extraKeys.add(NativeKeyEvent.VC_SPACE);
extraKeys.add(NativeKeyEvent.VC_TAB);
extraKeys.add(NativeKeyEvent.VC_BACKSPACE);
// Esc
extraKeys.add(NativeKeyEvent.VC_ESCAPE);
// Enter
extraKeys.add(NativeKeyEvent.VC_ENTER);
// Minus, plus, divided, multiplication
extraKeys.add(NativeKeyEvent.VC_KP_SUBTRACT);
extraKeys.add(NativeKeyEvent.VC_KP_ADD);
extraKeys.add(NativeKeyEvent.VC_KP_DIVIDE);
extraKeys.add(NativeKeyEvent.VC_KP_MULTIPLY);
}
示例15: 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;
}