-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add function to paste from clipboard and add support for non-US locales #1411
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
base: master
Are you sure you want to change the base?
Conversation
- 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).
|
Apologies about the delay in reviewing. Overall this looks great, but I am struggling a bit with this PR for several reasons:
|
|
I agree that these are all valid points.
The style (OO, exceptions and async) could be changed of course, but my general problem currently is that I'm too busy at work right now, and this will be the case throughout December.
The "locale" is the same, shared locale of host AND guest OS.
It's used for typing and pasting on desktop browsers and for typing on mobile browsers (never tried to paste into a mobile device, this might work). It may affect any character. Keyboard layouts are open and completely arbitrary, there are no rules. For example, on my German keyboard layout, the letters "y" and "z" are swapped (compared to the US-layout), and almost all non-alphanumeric characters are shuffled. The US-layout is not a complete subset of all layouts, the Italian layout lacks the tilde and backtick keys, for example. I think on all modern OSes, you can freely design keyboard layouts as you please. They even have their own subreddit for keyboard layouts, and it's actually quite active: https://www.reddit.com/r/KeyboardLayouts/. So there are no rules, only mappings for more or less popular keyboard layouts.
Agree (this currently is the US-layout, which is conceptually the same).
I know, but unfortunately neither Firefox nor Safari support this feature, that's why I didn't use it (and my guess is that they will never support it because of the problem with browser fingerprinting). |
How about providing additional keyboard maps as JSON files or modules? import custom_keymap from "./de-keymap.mjs";
const emulator = new V86({
...
keymap: custom_keymap,
});
// or
const emulator = new V86({
...
keymap_url: "./de_keymap.json",
}); |
Yes, that should be a nice way to solve this issue. The Python script An extreme option would be to not include any foreign keyboard layout mappings in the v86 main repository, just to support them technically. |
Like a file input section (along with some built-in layouts)? |
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
us,uk,de, default:us), each locale defines a codepage and a keyboard layout mappingAPI changes
delayargument fromV86.keyboard_send_scancodes()andV86.keyboard_send_text(), not needed any more (moved to KeyboardAdapter config)V86.keyboard_send_keys(codes, delay), this isn't supported any more (deprecated and wasn't used in the source tree anyway)V86.keyboard_send_keypress(keys, hold_time)as a replacement,keysis an array of strings in KeyboardEvent.code naming conventionoptions.localeto set the Locale at startup (default:us)Changes to class
KeyboardAdapterDesktopKeyboardandDataKeyboardclassesDemos
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:
Use case 3: German keyboard layout mapping and copdepage in vga2tty with FreeDOS 1.4 German:
See vga2tty.
freedos14-de-vga2tty-kbdgr.mp4
TODO