Skip to content

Conversation

chschnell
Copy link
Contributor

To paste text from the system clipboard into the emulator support for international keyboard layout mappings is needed for non-US users (in text mode, support for non-US codepages is additionally needed). This problem is laid out in detail in issue #1406.

User interface changes

  • added "Locale" setting to emulator setup (us, uk, de, default: us), each locale defines a codepage and a keyboard layout mapping
  • added "Send clipboard" function button to paste current system clipboard content into the emulator (can be aborted by pressing Esc)

API changes

  • removed delay argument from V86.keyboard_send_scancodes() and V86.keyboard_send_text(), not needed any more (moved to KeyboardAdapter config)
  • removed V86.keyboard_send_keys(codes, delay), this isn't supported any more (deprecated and wasn't used in the source tree anyway)
  • added V86.keyboard_send_keypress(keys, hold_time) as a replacement, keys is an array of strings in KeyboardEvent.code naming convention
  • added V86 configuration option options.locale to set the Locale at startup (default: us)

Changes to class KeyboardAdapter

  • split implementation into separate DesktopKeyboard and DataKeyboard classes
  • DesktopKeyboard handles interactive keyboard input from the system keyboard in desktop browser environments
  • DataKeyboard handles all other cases in which we feed an arbitrary large amount of data into the keyboard pipeline programatically, which can be a unicode string, a synthetic key-press event or a sequence of raw scancodes
  • for consistency, DesktopKeyboard is muted whenever DataKeyboard is feeding scancodes into the keyboard pipeline
  • removed dependencies on deprecated KeyboardEvent.keyCode (as much as possible, help needed)
  • removed charmap[] and asciimap[]
  • added KEYMAPS[], maps unicode characters to scancode combinations for selected keyboard layouts
  • moved away from using raw scancode numbers in the source tree in favour of string-typed key names from the KeyboardEvent.code naming convention

Demos

Use case 1: Pasting all extended German keys into nano (Debian 12 German in text console mode):
debian-de-paste-keyboard-kbdgr.mp4
Use case 2: Mobile screenshot FreeDOS 1.4 German:

freedos14-de-android-kbdgr

Use case 3: German keyboard layout mapping and copdepage in vga2tty with FreeDOS 1.4 German:

See vga2tty.

freedos14-de-vga2tty-kbdgr.mp4

TODO

  • tooling: keyboard layout mappings are currently generated by an external python script, this could be moved to ./tools/ in the source tree. The same is true for the generation of codepage mappings. Both scripts need a bit of work and discussion before though.
  • CapsLock: the CapsLock state of the system keyboard is currently ignored (the key itself is handled correctly, but its active/inactive state is not handled), haven't really looked into this yet
  • internal mapping objects for codepages, keyboard layouts and locales are currently scattered across lib.js, browser/keyboard.js and browser/starter.js (respectively), maybe these should be at the same place because they are related, but where?

- added class DesktopKeyboard, moved related code from KeyboardAdapter into new class.
- added class StringKeyboard, added KEYMAPS maps for US, UK and DE keyboards.
- added SCANCODE map, maps string KeyboardEvent.code names to integer scancodes (was: KeyboardAdapter.codemap).
- removed KeyboardAdapter.charmap, .asciimap and .codemap mappings.
- KeyboardAdapter now only filters events and hands off to DesktopKeyboard and StringKeyboard, as needed.
Literal key values of Javascript Objects are shortened in V86 release mode, in debug mode they are kept unchanged.

This lead to key lookup failures in mapping Object SCANCODE.

Changed type of keys to string in SCANCODE to fix this.
- removed "delay" arguments from V86.keyboard_send_scancodes() and V86.keyboard_send_text(), no longer needed
- removed function V86.keyboard_send_keys(codes, delay) entirely, we no longer support keyCode-to-scancode mappings
- likely fixed broken Enter and Backspace keys in mobile browers
Prevent Closure Compiler from renaming keys by using strings instead of literals.
Replaces no longer supported API function V86.keyboard_send_keys(codes, delay).
config.lang defines a "locale region" and serves as a shortcut for predefined pairs of keyboard layout and codepage identifieres.

Added three supported values for config.lang:
- "us": United States (KBDUS, CP437)
- "uk": United Kingdom (KBDUK, CP858)
- "de": Germany (KBDGR, CP858)
If defined, hold_time is the time in milliseconds for which the keys are pressed down (default: 0).
If a key name with a length larger than 1 is passed to send_keypress() then the pyhsical keyboard mapping SCANCODE[] is used to determine the scancode. All key names in the KeyboardEvent.code naming convention have at least a length of 2.

New: If a key name of length 1 is passed to send_keypress() then locale-dependent layout mapping KEYMAPS[] is used to determine the scancode. The raw scancode of the key's first (scancode, modifier) pair is used, modifier is ignored here.

This is a bit closer to the removed V86.keyboard_send_keys(codes, delay) (which was based on deprecated KeyboardEvent.keyCode).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant