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

The following examples show how to use java.awt.event.KeyEvent#KEY_LOCATION_STANDARD . 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: ActionCommand.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static InputEvent getInputEvent(String actionName) {
  final Shortcut[] shortcuts = KeymapManager.getInstance().getActiveKeymap().getShortcuts(actionName);
  KeyStroke keyStroke = null;
  for (Shortcut each : shortcuts) {
    if (each instanceof KeyboardShortcut) {
      keyStroke = ((KeyboardShortcut)each).getFirstKeyStroke();
      if (keyStroke != null) break;
    }
  }

  if (keyStroke != null) {
    return new KeyEvent(JOptionPane.getRootFrame(),
                                           KeyEvent.KEY_PRESSED,
                                           System.currentTimeMillis(),
                                           keyStroke.getModifiers(),
                                           keyStroke.getKeyCode(),
                                           keyStroke.getKeyChar(),
                                           KeyEvent.KEY_LOCATION_STANDARD);
  } else {
    return new MouseEvent(JOptionPane.getRootFrame(), MouseEvent.MOUSE_PRESSED, 0, 0, 0, 0, 1, false, MouseEvent.BUTTON1);
  }


}
 
Example 2
Source File: PS2.java    From OberonEmulator with ISC License 5 votes vote down vote up
public int[] encodeNative(int location, int keyCode, boolean press, boolean includeCharBased) {
	int value = vkMap[location][keyCode];
	if (value == 0 && vkMap[KeyEvent.KEY_LOCATION_STANDARD][keyCode] != 0)
		System.out.println("Key " + keyCode + " exists as standard but not as " + location);
	VK_TYPE type = VK_TYPE.values()[value >> 8];
	if (value == 0 || (type == VK_TYPE.CHAR_BASED && !includeCharBased))
		return new int[0];
	value = value & 0xFF;
	switch (type) {
	case CHAR_BASED:
	case NORMAL:
		if (press)
			return new int[] { value };
		else
			return new int[] { 0xF0, value };
	case EXTENDED:
		if (press)
			return new int[] { 0xE0, value };
		else
			return new int[] { 0xE0, 0xF0, value };
	case NUMLOCK_HACK:
		if (press)
			return new int[] { 0xE0, 0x12, 0xE0, value };
		else
			return new int[] { 0xE0, 0xF0, value, 0xE0, 0xF0, 0x12 };
	case SHIFT_HACK:
		if (press)
			return new int[] { 0xE0, 0xF0, 0x12, 0xE0, 0xF0, 0x59, 0xE0, value };
		else
			return new int[] { 0xE0, 0xF0, value };
	}
	return new int[0];
}