Mercurial > 510Connectbot
comparison src/com/five_ten_sg/connectbot/service/TerminalKeyListener.java @ 156:4e1e1a6ee9f9
allow button shortcuts to see key up/down, so the monitor key can toggle properly
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 23 Jun 2014 18:23:34 -0700 |
parents | 86f903100573 |
children | 269de016813d |
comparison
equal
deleted
inserted
replaced
155:156b53fc4815 | 156:4e1e1a6ee9f9 |
---|---|
143 int repeat = event.getRepeatCount(); | 143 int repeat = event.getRepeatCount(); |
144 | 144 |
145 // skip keys if we aren't connected yet or have been disconnected | 145 // skip keys if we aren't connected yet or have been disconnected |
146 if (bridge.isDisconnected()) return false; | 146 if (bridge.isDisconnected()) return false; |
147 | 147 |
148 // short cuts can see repeat counts and key up/down | |
149 if handleShortcuts(v, event, repeat, (event.getAction() == KeyEvent.ACTION_DOWN) return true; | |
150 | |
148 // Ignore all key-up events except for the special keys | 151 // Ignore all key-up events except for the special keys |
149 if (event.getAction() == KeyEvent.ACTION_UP) { | 152 if (event.getAction() == KeyEvent.ACTION_UP) { |
150 // There's nothing here for virtual keyboard users. | 153 // There's nothing else here for virtual keyboard users. |
151 if (!hardKeyboard || hardKeyboardHidden) return false; | 154 if (!hardKeyboard || hardKeyboardHidden) return false; |
152 | 155 |
153 // if keycode debugging enabled, log and print the pressed key | 156 // if keycode debugging enabled, log and print the pressed key |
154 if (prefs.getBoolean(PreferenceConstants.DEBUG_KEYCODES, false)) { | 157 if (prefs.getBoolean(PreferenceConstants.DEBUG_KEYCODES, false)) { |
155 String keyCodeString = String.format(": %d", keyCode); | 158 String keyCodeString = String.format(": %d", keyCode); |
457 buffer.keyPressed(vt320.KEY_END, ' ', getStateForBuffer()); | 460 buffer.keyPressed(vt320.KEY_END, ' ', getStateForBuffer()); |
458 metaState &= ~META_TRANSIENT; | 461 metaState &= ~META_TRANSIENT; |
459 bridge.tryKeyVibrate(); | 462 bridge.tryKeyVibrate(); |
460 return true; | 463 return true; |
461 | 464 |
462 case KeyEvent.KEYCODE_CAMERA: | |
463 // check to see which shortcut the camera button triggers | |
464 String hwbuttonShortcut = manager.prefs.getString( | |
465 PreferenceConstants.CAMERA, | |
466 PreferenceConstants.HWBUTTON_SCREEN_CAPTURE); | |
467 return (handleShortcut(v, hwbuttonShortcut, repeat)); | |
468 | |
469 case KeyEvent.KEYCODE_VOLUME_UP: | |
470 // check to see which shortcut the volume button triggers | |
471 hwbuttonShortcut = manager.prefs.getString( | |
472 PreferenceConstants.VOLUP, | |
473 PreferenceConstants.HWBUTTON_CTRL); | |
474 return (handleShortcut(v, hwbuttonShortcut, repeat)); | |
475 | |
476 case KeyEvent.KEYCODE_VOLUME_DOWN: | |
477 // check to see which shortcut the camera button triggers | |
478 hwbuttonShortcut = manager.prefs.getString( | |
479 PreferenceConstants.VOLDN, | |
480 PreferenceConstants.HWBUTTON_TAB); | |
481 return (handleShortcut(v, hwbuttonShortcut, repeat)); | |
482 | |
483 case KeyEvent.KEYCODE_SEARCH: | |
484 // check to see which shortcut the search button triggers | |
485 hwbuttonShortcut = manager.prefs.getString( | |
486 PreferenceConstants.SEARCH, | |
487 PreferenceConstants.HWBUTTON_ESC); | |
488 return (handleShortcut(v, hwbuttonShortcut, repeat)); | |
489 | |
490 case KeyEvent.KEYCODE_BUTTON_L2: | |
491 // check to see which shortcut the ptt button triggers | |
492 hwbuttonShortcut = manager.prefs.getString( | |
493 PreferenceConstants.PTT, | |
494 PreferenceConstants.HWBUTTON_MONITOR); | |
495 return (handleShortcut(v, hwbuttonShortcut, repeat)); | |
496 | |
497 case KeyEvent.KEYCODE_DEL: | 465 case KeyEvent.KEYCODE_DEL: |
498 if ((metaState & META_ALT_MASK) != 0) { | 466 if ((metaState & META_ALT_MASK) != 0) { |
499 buffer.keyPressed(vt320.KEY_INSERT, ' ', getStateForBuffer()); | 467 buffer.keyPressed(vt320.KEY_INSERT, ' ', getStateForBuffer()); |
500 } | 468 } |
501 else { | 469 else { |
597 } | 565 } |
598 | 566 |
599 return false; | 567 return false; |
600 } | 568 } |
601 | 569 |
602 private boolean handleShortcut(View v, String shortcut, int repeat) { | 570 private boolean handleShortcuts(View v, int keyCode, KeyEvent event, int repeat, boolean down) { |
571 switch (keyCode) { | |
572 case KeyEvent.KEYCODE_CAMERA: | |
573 // check to see which shortcut the camera button triggers | |
574 String hwbuttonShortcut = manager.prefs.getString( | |
575 PreferenceConstants.CAMERA, | |
576 PreferenceConstants.HWBUTTON_SCREEN_CAPTURE); | |
577 return (handleShortcut(v, hwbuttonShortcut, repeat, down)); | |
578 | |
579 case KeyEvent.KEYCODE_VOLUME_UP: | |
580 // check to see which shortcut the volume button triggers | |
581 hwbuttonShortcut = manager.prefs.getString( | |
582 PreferenceConstants.VOLUP, | |
583 PreferenceConstants.HWBUTTON_CTRL); | |
584 return (handleShortcut(v, hwbuttonShortcut, repeat, down)); | |
585 | |
586 case KeyEvent.KEYCODE_VOLUME_DOWN: | |
587 // check to see which shortcut the camera button triggers | |
588 hwbuttonShortcut = manager.prefs.getString( | |
589 PreferenceConstants.VOLDN, | |
590 PreferenceConstants.HWBUTTON_TAB); | |
591 return (handleShortcut(v, hwbuttonShortcut, repeat, down)); | |
592 | |
593 case KeyEvent.KEYCODE_SEARCH: | |
594 // check to see which shortcut the search button triggers | |
595 hwbuttonShortcut = manager.prefs.getString( | |
596 PreferenceConstants.SEARCH, | |
597 PreferenceConstants.HWBUTTON_ESC); | |
598 return (handleShortcut(v, hwbuttonShortcut, repeat, down)); | |
599 | |
600 case KeyEvent.KEYCODE_BUTTON_L2: | |
601 // check to see which shortcut the ptt button triggers | |
602 hwbuttonShortcut = manager.prefs.getString( | |
603 PreferenceConstants.PTT, | |
604 PreferenceConstants.HWBUTTON_MONITOR); | |
605 return (handleShortcut(v, hwbuttonShortcut, repeat, down)); | |
606 | |
607 default: return false; | |
608 } | |
609 } | |
610 | |
611 private boolean handleShortcut(View v, String shortcut, int repeat, boolean down) { | |
603 if (PreferenceConstants.HWBUTTON_SCREEN_CAPTURE.equals(shortcut)) { | 612 if (PreferenceConstants.HWBUTTON_SCREEN_CAPTURE.equals(shortcut)) { |
604 if (repeat > 0) return false; | 613 if (repeat > 0) return false; |
614 if (!down) return false; | |
605 bridge.captureScreen(); | 615 bridge.captureScreen(); |
606 } | 616 } |
607 else if (PreferenceConstants.HWBUTTON_MONITOR.equals(shortcut)) { | 617 else if (PreferenceConstants.HWBUTTON_MONITOR.equals(shortcut)) { |
608 if (repeat > 0) return false; | 618 if (repeat > 0) return false; |
609 buffer.monitorKey(true); // key down | 619 buffer.monitorKey(down); |
610 } | 620 } |
611 else if (PreferenceConstants.HWBUTTON_CTRL.equals(shortcut)) { | 621 else if (PreferenceConstants.HWBUTTON_CTRL.equals(shortcut)) { |
622 if (!down) return false; | |
612 showMetakeyToast(v, PreferenceConstants.HWBUTTON_CTRL); | 623 showMetakeyToast(v, PreferenceConstants.HWBUTTON_CTRL); |
613 metaPress(META_CTRL_ON); | 624 metaPress(META_CTRL_ON); |
614 } | 625 } |
615 else if (PreferenceConstants.HWBUTTON_TAB.equals(shortcut)) { | 626 else if (PreferenceConstants.HWBUTTON_TAB.equals(shortcut)) { |
627 if (!down) return false; | |
616 buffer.keyPressed(vt320.KEY_TAB, ' ', getStateForBuffer()); | 628 buffer.keyPressed(vt320.KEY_TAB, ' ', getStateForBuffer()); |
617 } | 629 } |
618 else if (PreferenceConstants.HWBUTTON_CTRLA_SPACE.equals(shortcut)) { | 630 else if (PreferenceConstants.HWBUTTON_CTRLA_SPACE.equals(shortcut)) { |
631 if (!down) return false; | |
619 buffer.write(0x01); | 632 buffer.write(0x01); |
620 buffer.write(' '); | 633 buffer.write(' '); |
621 } | 634 } |
622 else if (PreferenceConstants.HWBUTTON_CTRLA.equals(shortcut)) { | 635 else if (PreferenceConstants.HWBUTTON_CTRLA.equals(shortcut)) { |
636 if (!down) return false; | |
623 buffer.write(0x01); | 637 buffer.write(0x01); |
624 } | 638 } |
625 else if (PreferenceConstants.HWBUTTON_ESC.equals(shortcut)) { | 639 else if (PreferenceConstants.HWBUTTON_ESC.equals(shortcut)) { |
640 if (!down) return false; | |
626 showMetakeyToast(v, PreferenceConstants.HWBUTTON_ESC); | 641 showMetakeyToast(v, PreferenceConstants.HWBUTTON_ESC); |
627 sendEscape(); | 642 sendEscape(); |
628 } | 643 } |
629 else if (PreferenceConstants.HWBUTTON_ESC_A.equals(shortcut)) { | 644 else if (PreferenceConstants.HWBUTTON_ESC_A.equals(shortcut)) { |
645 if (!down) return false; | |
630 sendEscape(); | 646 sendEscape(); |
631 buffer.write('a'); | 647 buffer.write('a'); |
632 } | 648 } |
633 else { | 649 else { |
634 return (false); | 650 return (false); |