Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect keyboard handling on Windows #160

Open
8 tasks
LinqLover opened this issue May 25, 2022 · 9 comments
Open
8 tasks

Incorrect keyboard handling on Windows #160

LinqLover opened this issue May 25, 2022 · 9 comments

Comments

@LinqLover
Copy link
Collaborator

LinqLover commented May 25, 2022

So far, I stumbled upon the following keyboard gestures that are currently not supported in Windows:

  • Alt + <letter> (e.g., for print it, do it, etc.)
  • Alt + Shift + <letter> (e.g., for debug it, preferences, etc.)
  • Alt + . or Ctrl + . for interrupt
  • Qwertz layout specific:
    • ^ , (to type a ^)
    • Ctrl + Alt + ß for \ and the analogous shortcuts for {, [, ], }, |
  • Alt + Home or Alt + End for navigation
  • Just pressing Alt should not set the keyboard focus to the window bar menu of the VM
@fniephaus
Copy link
Member

Are you sure Alt is not accidentally mapped to something else, like the Win key?

@LinqLover
Copy link
Collaborator Author

Pressing Alt + P has the same effect as pressing just P. Every key that is pressed together with Ctrl + Alt or AltGr is completely ignored. Windows shortcuts work as usual.

By the way, there are further weird things going on. This is how the keyboard exerciser looks like after typing aA1:

image
image

Typing p even raises an error because the keyCode 112 is not registered in the virtualKeyTable. It's interesting that simple typing in text editors still works at all. :-)

keyDowns look no better:

image

@fniephaus
Copy link
Member

The root cause for all of this is that the OpenSmalltalkVM provides different events on different platforms and because of this, Squeak has covered this up on the image side. TruffleSqueak is very consistent because it's using Java AWT/Swing but that breaks on the image level. I guess you can tell that I don't use Windows much myself. Any contributions that makes this better are more than welcome. The KeyboardListener is actually quite simple:

public final class SqueakKeyboard implements KeyListener {
private final SqueakDisplay display;
public SqueakKeyboard(final SqueakDisplay display) {
this.display = display;
}
@Override
public void keyPressed(final KeyEvent e) {
display.recordModifiers(e);
final int keyChar = toKeyChar(e);
addKeyboardEvent(KEYBOARD_EVENT.DOWN, keyChar != KeyEvent.CHAR_UNDEFINED ? keyChar : e.getKeyCode());
if (keyChar != KeyEvent.CHAR_UNDEFINED) {
addKeyboardEvent(KEYBOARD_EVENT.CHAR, keyChar);
}
if (e.isMetaDown() && keyChar == '.') {
display.image.interrupt.setInterruptPending();
}
}
@Override
public void keyTyped(final KeyEvent e) {
/** Keyboard char events handled in keyPressed(KeyEvent). */
}
@Override
public void keyReleased(final KeyEvent e) {
display.recordModifiers(e);
final int keyChar = toKeyChar(e);
addKeyboardEvent(KEYBOARD_EVENT.UP, keyChar != KeyEvent.CHAR_UNDEFINED ? keyChar : e.getKeyCode());
}
private void addKeyboardEvent(final long eventType, final int keyCharOrCode) {
display.addEvent(EVENT_TYPE.KEYBOARD, keyCharOrCode, eventType, display.buttons >> 3, keyCharOrCode);
}
private static int toKeyChar(final KeyEvent e) {
//@formatter:off
switch(e.getKeyCode()) { // Handle special keys.
case KeyEvent.VK_BACK_SPACE: return 8;
case KeyEvent.VK_TAB: return 9;
case KeyEvent.VK_ENTER: return 13;
case KeyEvent.VK_ESCAPE: return 27;
case KeyEvent.VK_SPACE: return 32;
case KeyEvent.VK_PAGE_UP: return 11;
case KeyEvent.VK_PAGE_DOWN: return 12;
case KeyEvent.VK_END: return 4;
case KeyEvent.VK_HOME: return 1;
case KeyEvent.VK_LEFT: return 28;
case KeyEvent.VK_UP: return 30;
case KeyEvent.VK_RIGHT: return 29;
case KeyEvent.VK_DOWN: return 31;
case KeyEvent.VK_INSERT: return 5;
case KeyEvent.VK_DELETE: return 127;
default: return e.getKeyChar();
}
//@formatter:on
}
}

@LinqLover
Copy link
Collaborator Author

Thanks for the pointers. So I'm no longer confused that most of these shortcuts do not work in WSL/VcXsrv either. If the problem might be on the image side, I'll also talk with @marceltaeumel about it. :-)

@fniephaus
Copy link
Member

We once thought about letting TruffleSqueak always prepend to run on Linux because of this. But then you of course run into many other problems (e.g., when trying to access the file system with the wrong delimiters).

@LinqLover
Copy link
Collaborator Author

Hm ... maybe we should introduce a new "omniplatform" type on the image side? SqueakJS might benefit from that as well.

@fniephaus
Copy link
Member

Yes, that'd be nice!

@fniephaus
Copy link
Member

FWIW, I just pushed 8b03140 which also seems to fix some of the other items on your list.

@LinqLover
Copy link
Collaborator Author

LinqLover commented Dec 18, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants