Java Code Examples for java.awt.event.KeyEvent#VK_PAUSE

The following examples show how to use java.awt.event.KeyEvent#VK_PAUSE . 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: ShortcutAndMenuKeyEventProcessor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public boolean dispatchKeyEvent(KeyEvent ev) {
       log.fine("dispatchKeyEvent ev: " + ev.paramString()
       + " source:" + ev.getSource().getClass().getName());
       // in some ctx, may need event filtering
       if (NbKeymap.getContext().length != 0) {
           // Ignore anything but KeyPressed inside ctx, #67187
           if (ev.getID() != KeyEvent.KEY_PRESSED) {
               ev.consume();
               return true;
           }
           
           skipNextTyped = true;

           Component comp = ev.getComponent();
           if (!(comp instanceof JComponent) ||
               ((JComponent)comp).getClientProperty("context-api-aware") == null) {
                   // not context api aware, don't pass subsequent events
               processShortcut(ev);
               // ignore processShortcut result, consume everything while in ctx
               return true; 
           }
       }

       if (ev.getID() == KeyEvent.KEY_PRESSED
           && ev.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK)
           && (ev.getKeyCode() == KeyEvent.VK_PAUSE
               || ev.getKeyCode() == KeyEvent.VK_CANCEL)
           ) {
           Object source = ev.getSource();
           if (source instanceof Component) {
               Component focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
               System.err.println("*** ShortcutAndMenuKeyEventProcessor: current focus owner = " + focused); // NOI18N
           }
           ev.consume();
           return true;
       }
       

// multi-shortcut in middle
       if (ev.getID() == KeyEvent.KEY_TYPED && skipNextTyped) {
           ev.consume();
           skipNextTyped = false;
           return true;
       }

       if (ev.getID() == KeyEvent.KEY_RELEASED) {
           skipNextTyped = false;
       }
       
       if (ev.getID() == KeyEvent.KEY_PRESSED) {
           // decompose to primitive fields to avoid memory profiler confusion (keyEvent keeps source reference)
           lastKeyChar = ev.getKeyChar();
           lastModifiers = ev.getModifiers();
           lastSampled = true;
       }
       
       MenuElement[] arr = MenuSelectionManager.defaultManager().getSelectedPath();
       if (arr == null || arr.length == 0) {
           wasPopupDisplayed = false;

           // Only here for fix #41477:
           // To be able to catch and dispatch Ctrl+TAB and Ctrl+Shift+Tab
           // in our own way, it's needed to do as soon as here, because
           // otherwise Swing will use these keys as focus traversals, which 
           // means that TopComponent which contains focusCycleRoot inside itself
           // will grab these shortcuts, which is not desirable 
           return KeyboardPopupSwitcher.processShortcut(ev);
       }

       if (!wasPopupDisplayed
           && lastSampled == true
           && ev.getID() == KeyEvent.KEY_TYPED
           && lastModifiers == InputEvent.ALT_MASK
           && ev.getModifiers() == InputEvent.ALT_MASK
           && lastKeyChar == ev.getKeyChar()
           ) {
           wasPopupDisplayed = true;
           ev.consume();
           return true;
       }

       wasPopupDisplayed = true;
       
       MenuSelectionManager.defaultManager().processKeyEvent(ev);
       
       // commented out as #130919 fix - I don't know why this was here, but
       // it did prevent keyboard functioning in menus in dialogs
       /*if (!ev.isConsumed() && arr != null && arr.length > 0 && arr[0] instanceof JMenuBar) {
           ev.setSource(WindowManagerImpl.getInstance().getMainWindow());
       }*/
       
       return ev.isConsumed();
   }
 
Example 2
Source File: GOSwingEventConverter.java    From settlers-remake with MIT License 4 votes vote down vote up
private String getKeyName(KeyEvent e) {
	String text = KeyEvent.getKeyText(e.getKeyCode());
	if (text == null || text.length() != 1) {
		switch (e.getKeyCode()) {
		case KeyEvent.VK_LEFT:
			text = "LEFT";
			break;
		case KeyEvent.VK_RIGHT:
			text = "RIGHT";
			break;
		case KeyEvent.VK_DOWN:
			text = "DOWN";
			break;
		case KeyEvent.VK_UP:
			text = "UP";
			break;
		case KeyEvent.VK_PAUSE:
			text = "PAUSE";
			break;
		case KeyEvent.VK_F1:
			text = "F1";
			break;
		case KeyEvent.VK_F2:
			text = "F2";
			break;
		case KeyEvent.VK_F3:
			text = "F3";
			break;
		case KeyEvent.VK_F4:
			text = "F4";
			break;
		case KeyEvent.VK_F5:
			text = "F5";
			break;
		case KeyEvent.VK_F6:
			text = "F6";
			break;
		case KeyEvent.VK_F7:
			text = "F7";
			break;
		case KeyEvent.VK_F8:
			text = "F8";
			break;
		case KeyEvent.VK_F9:
			text = "F9";
			break;
		case KeyEvent.VK_F10:
			text = "F10";
			break;
		case KeyEvent.VK_F11:
			text = "F11";
			break;
		case KeyEvent.VK_F12:
			text = "F12";
			break;
		case KeyEvent.VK_PLUS:
			text = "+";
			break;
		case KeyEvent.VK_MINUS:
			text = "-";
			break;
		case KeyEvent.VK_DELETE:
			text = "DELETE";
			break;
		case KeyEvent.VK_SPACE:
			text = " ";
			break;
		case KeyEvent.VK_ESCAPE:
			text = "ESCAPE";
			break;
		case KeyEvent.VK_BACK_SPACE:
			text = "BACK_SPACE";
			break;
		case KeyEvent.VK_TAB:
			text = "TAB";
			break;
		default:
			text = "" + e.getKeyChar();
		}
	}
	return text;
}