Java Code Examples for javafx.scene.input.KeyEvent#getCharacter()

The following examples show how to use javafx.scene.input.KeyEvent#getCharacter() . 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: ShowPanel.java    From oim-fx with MIT License 6 votes vote down vote up
public void processKeyEvent(KeyEvent ev) {
	if (webPage == null)
		return;
	ev.consume();
	String text = null;
	String keyIdentifier = null;
	int windowsVirtualKeyCode = 0;
	if (ev.getEventType() == KeyEvent.KEY_TYPED) {
		text = ev.getCharacter();
	} else {
		KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode());
		keyIdentifier = keyCodeEntry.getKeyIdentifier();
		windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode();
	}

	WCKeyEvent keyEvent = new WCKeyEvent(
			idMap.get(ev.getEventType()),
			text,
			keyIdentifier,
			windowsVirtualKeyCode,
			ev.isShiftDown(), ev.isControlDown(),
			ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis());
	if (webPage.dispatchKeyEvent(keyEvent)) {
		ev.consume();
	}
}
 
Example 2
Source File: WebViewEventDispatcher.java    From oim-fx with MIT License 6 votes vote down vote up
private void processKeyEvent(KeyEvent ev) {
    if (page == null) return;

    String text = null;
    String keyIdentifier = null;
    int windowsVirtualKeyCode = 0;
    if(ev.getEventType() == KeyEvent.KEY_TYPED) {
        text = ev.getCharacter();
    } else {
        KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode());
        keyIdentifier = keyCodeEntry.getKeyIdentifier();
        windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode();
    }

    WCKeyEvent keyEvent = new WCKeyEvent(
            idMap.get(ev.getEventType()),
            text,
            keyIdentifier,
            windowsVirtualKeyCode,
            ev.isShiftDown(), ev.isControlDown(),
            ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis());
    if (page.dispatchKeyEvent(keyEvent)) {
        ev.consume();
    }
}
 
Example 3
Source File: WritePane.java    From oim-fx with MIT License 6 votes vote down vote up
private void processKeyEvent(KeyEvent ev) {
	if (webPage == null)
		return;

	String text = null;
	String keyIdentifier = null;
	int windowsVirtualKeyCode = 0;
	if (ev.getEventType() == KeyEvent.KEY_TYPED) {
		text = ev.getCharacter();
	} else {
		KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode());
		keyIdentifier = keyCodeEntry.getKeyIdentifier();
		windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode();
	}
	System.out.println(ev.getText());
	WCKeyEvent keyEvent = new WCKeyEvent(
			idMap.get(ev.getEventType()),
			text,
			keyIdentifier,
			windowsVirtualKeyCode,
			ev.isShiftDown(), ev.isControlDown(),
			ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis());
	if (webPage.dispatchKeyEvent(keyEvent)) {
		ev.consume();
	}
}
 
Example 4
Source File: Controller.java    From everywhere with Apache License 2.0 6 votes vote down vote up
public void getKeyTyped(KeyEvent keyEvent) {
    if ("\b".equals(keyEvent.getCharacter()) && !searchText.isEmpty()) {
        searchText = searchText.substring(0, searchText.length() - 1);
    } else {
        if (!keyEvent.getCharacter().contains("\\")) {
           searchText += keyEvent.getCharacter();
        }
    }
    System.out.println(searchText);
    if (!searchText.isEmpty()) {
        List<SearchedResult> searchedResults = getSearchResult(searchText, searchField);
        showTableData(searchedResults);
    } else {
        tview.getItems().clear();
    }
}
 
Example 5
Source File: KeyHelper.java    From AsciidocFX with Apache License 2.0 6 votes vote down vote up
public static boolean isEnter(KeyEvent event) {
    boolean enter = false;

    enter = ENTER.match(event);

    if (!enter) {
        if (isUndefined(event)) {
            String character = event.getCharacter();
            if (character.matches("\\R")) {
                enter = true;
            }
        }
    }

    return enter;
}
 
Example 6
Source File: WritePanel.java    From oim-fx with MIT License 5 votes vote down vote up
public void processKeyEvent(KeyEvent ev) {
	if (webPage == null)
		return;
	ev.consume();
	String text = null;
	String keyIdentifier = null;
	int windowsVirtualKeyCode = 0;
	if (ev.getEventType() == KeyEvent.KEY_TYPED) {
		text = ev.getCharacter();
	} else {
		System.out.println(ev.getCode());
		KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode());
		keyIdentifier = keyCodeEntry.getKeyIdentifier();
		windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode();
	}

	WCKeyEvent keyEvent = new WCKeyEvent(
			idMap.get(ev.getEventType()),
			text,
			keyIdentifier,
			windowsVirtualKeyCode,
			ev.isShiftDown(), ev.isControlDown(),
			ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis());
	if (webPage.dispatchKeyEvent(keyEvent)) {
		ev.consume();
	}
}
 
Example 7
Source File: ChatShowPane.java    From oim-fx with MIT License 5 votes vote down vote up
public void processKeyEvent(KeyEvent ev) {
	if (webPage == null){
		return;
	}
	ev.consume();
	String text = null;
	String keyIdentifier = null;
	int windowsVirtualKeyCode = 0;
	if (ev.getEventType() == KeyEvent.KEY_TYPED) {
		text = ev.getCharacter();
	} else {
		KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode());
		keyIdentifier = keyCodeEntry.getKeyIdentifier();
		windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode();
	}

	WCKeyEvent keyEvent = new WCKeyEvent(
			idMap.get(ev.getEventType()),
			text,
			keyIdentifier,
			windowsVirtualKeyCode,
			ev.isShiftDown(), ev.isControlDown(),
			ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis());
	if (webPage.dispatchKeyEvent(keyEvent)) {
		ev.consume();
	}
}
 
Example 8
Source File: ChatWritePane.java    From oim-fx with MIT License 5 votes vote down vote up
public void processKeyEvent(KeyEvent ev) {
	if (webPage == null)
		return;
	ev.consume();
	String text = null;
	String keyIdentifier = null;
	int windowsVirtualKeyCode = 0;
	if (ev.getEventType() == KeyEvent.KEY_TYPED) {
		text = ev.getCharacter();
	} else {
		System.out.println(ev.getCode());
		KeyCodeMap.Entry keyCodeEntry = KeyCodeMap.lookup(ev.getCode());
		keyIdentifier = keyCodeEntry.getKeyIdentifier();
		windowsVirtualKeyCode = keyCodeEntry.getWindowsVirtualKeyCode();
	}

	WCKeyEvent keyEvent = new WCKeyEvent(
			idMap.get(ev.getEventType()),
			text,
			keyIdentifier,
			windowsVirtualKeyCode,
			ev.isShiftDown(), ev.isControlDown(),
			ev.isAltDown(), ev.isMetaDown(), System.currentTimeMillis());
	if (webPage.dispatchKeyEvent(keyEvent)) {
		ev.consume();
	}
}
 
Example 9
Source File: ConsoleKeyEvent.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handle (KeyEvent e)                     // onKeyTyped
{
  if (e.getEventType () != KeyEvent.KEY_TYPED)
    return;
  String c = e.getCharacter ();
  if (c.isEmpty ())
    return;
  char ch = c.charAt (0);

  if (screen.isKeyboardLocked () || e.isMetaDown () || e.isControlDown ()
      || e.isAltDown ())
  {
    // seems to be a bug in java
    if (e.isMetaDown ())
    {
      if (ch == '-')                    // osx fix
      {
        screen.getFontManager ().smaller ();
        e.consume ();
      }
      else if (ch == '=')               // osx fix
      {
        screen.getFontManager ().bigger ();
        e.consume ();
      }
    }

    return;
  }

  if (ch >= 32 && ch < 0x7F)
  {
    cursor.typeChar ((byte) Dm3270Utility.asc2ebc[ch]);
    e.consume ();
  }
}
 
Example 10
Source File: ConsoleKeyEvent.java    From dm3270 with Apache License 2.0 5 votes vote down vote up
@Override
public void handle (KeyEvent e)                     // onKeyTyped
{
  if (e.getEventType () != KeyEvent.KEY_TYPED)
    return;
  String c = e.getCharacter ();
  if (c.isEmpty ())
    return;
  char ch = c.charAt (0);

  if (screen.isKeyboardLocked () || e.isMetaDown () || e.isControlDown ()
      || e.isAltDown ())
  {
    // seems to be a bug in java
    if (e.isMetaDown ())
    {
      if (ch == '-')                    // osx fix
      {
        screen.getFontManager ().smaller ();
        e.consume ();
      }
      else if (ch == '=')               // osx fix
      {
        screen.getFontManager ().bigger ();
        e.consume ();
      }
    }

    return;
  }

  if (ch >= 32 && ch < 0x7F)
  {
    cursor.typeChar ((byte) Dm3270Utility.asc2ebc[ch]);
    e.consume ();
  }
}
 
Example 11
Source File: SceneKeyTypedHandler.java    From stagedisplayviewer with MIT License 5 votes vote down vote up
@Override
public void handle(KeyEvent keyEvent) {
    switch (keyEvent.getCharacter()) {
        case "f" :
        case "F" :
            stage.setFullScreen(!stage.isFullScreen());
            break;
        default :
            break;
    }
}
 
Example 12
Source File: GenericStyledAreaBehavior.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void keyTyped(KeyEvent event) {
    String text = event.getCharacter();
    int n = text.length();

    if(n == 0) {
        return;
    }

    view.replaceSelection(text);
}
 
Example 13
Source File: KeyMap.java    From FxDock with Apache License 2.0 4 votes vote down vote up
protected static KKey key(KeyEvent ev)
	{
		int flags = 0;
		KeyCode cd;
		String ch;
		
		if(ev.getEventType() == KeyEvent.KEY_PRESSED)
		{
			flags |= KEY_PRESSED;
			cd = ev.getCode();
			ch = null;
		}
		else if(ev.getEventType() == KeyEvent.KEY_RELEASED)
		{
			flags |= KEY_RELEASED;
			cd = ev.getCode();
			ch = null;
		}
		else if(ev.getEventType() == KeyEvent.KEY_TYPED)
		{
			flags |= KEY_TYPED;
			cd = null;
			ch = ev.getCharacter();
		}
		else
		{
			throw new Error("?" + ev.getEventType());
		}
		
		if(ev.isAltDown())
		{
			flags |= ALT;
		}
		
		if(ev.isControlDown())
		{
			flags |= CTRL;
		}

		if(ev.isMetaDown())
		{
			flags |= META;
		}

		if(ev.isShiftDown())
		{
			flags |= SHIFT;
		}
		
		if(ev.isShortcutDown())
		{
			flags |= ACTUAL_SHORTCUT;
		}
		
//		D.f("key event 0x%8x %s", flags, ev.getCode());
		
		return new KKey(flags, cd, ch);
	}