The OpenD Programming Language

KeyboardEvent

The new style of keyboard event

Worth noting some special cases terminals tend to do:

  • Ctrl+space bar sends char 0.
  • Ctrl+ascii characters send char 1 - 26 as chars on all systems. Ctrl+shift+ascii is generally not recognizable on Linux, but works on Windows and with my terminal emulator on all systems. Alt+ctrl+ascii, for example Alt+Ctrl+F, is sometimes sent as modifierState = alt|ctrl, key = 'f'. Sometimes modifierState = alt|ctrl, key = 'F'. Sometimes modifierState = ctrl|alt, key = 6. Which one you get depends on the system/terminal and the user's caps lock state. You're probably best off checking all three and being aware it might not work at all.
  • Some combinations like ctrl+i are indistinguishable from other keys like tab.
  • Other modifier+key combinations may send random other things or not be detected as it is configuration-specific with no way to detect. It is reasonably reliable for the non-character keys (arrows, F1-F12, Home/End, etc.) but not perfectly so. Some systems just don't send them. If they do though, terminal will try to set modifierState.
  • Alt+key combinations do not generally work on Windows since the operating system uses that combination for something else. The events may come to you, but it may also go to the window menu or some other operation too. In fact, it might do both!
  • Shift is sometimes applied to the character, sometimes set in modifierState, sometimes both, sometimes neither.
  • On some systems, the return key sends \r and some sends \n.

Members

Enums

Key
enum Key

Represents non-character keys.

ProprietaryPseudoKeys
enum ProprietaryPseudoKeys

These are extensions added for better interop with the embedded emulator. As characters inside the unicode private-use area, you shouldn't encounter them unless you opt in by using some other proprietary feature.

Functions

isCharacter
bool isCharacter()

Returns true if the event was a normal typed character.

isNonCharacterKey
bool isNonCharacterKey()

Returns true if the key represents one of the range named entries in the Key enum. This does not necessarily mean it IS one of the named entries, just that it is in the range. Checking more precisely would require a loop in here and you are better off doing that in your own switch statement, with a do-nothing default.

isProprietary
bool isProprietary()
isUnmodifiedCharacter
bool isUnmodifiedCharacter()

Returns true if this keyboard event represents a normal character keystroke, with no extraordinary modifier keys depressed.

Variables

modifierState
uint modifierState;
pressed
bool pressed;
which
dchar which;

Meta