plover icon indicating copy to clipboard operation
plover copied to clipboard

incorrect strokes on Plover causes issues on wsl2 with vim

Open Josiah-tan opened this issue 2 years ago • 1 comments

Describe the bug for some reason vim on wsl2 just doesn't work when you give it incorrect strokes

To Reproduce

Steps to reproduce the behavior:

So to address this problem, let's say that I open a new file main.txt, I then go into insert mode and stroke "Hello world" so that works fine, but then when I type STKPWHR which is an incorrect stroke that does not exist in the dictionary for me

Expected behavior

what I would expect is the lines "Hello world STKPWHR" being printed out on the vim editor
(this is from within my Linux virtual machine which works fine) image

Screenshots but instead what I get is this: image

Operating system

  • OS: [e.g. Windows 10]

image

  • Plover Version

image

Hardware

I use arpeggiate mode with my laptop keyboard with plover (hoping to get hardware soon), however this problem still persists without arpeggiate mode

Josiah-tan avatar Oct 02 '21 04:10 Josiah-tan

Caused by Plover always sending scanCode to be 0.

Temporary patch: (might still fail for extended keys)

The list of scan codes is from my machine.

Related issue about Windows scan code: https://github.com/openstenoproject/plover/issues/1154

commit f1ac3be69d2356bfe3055651da7af74b24a70510
Author: user202729 <[email protected]>
Date:   Sat Oct 2 22:16:02 2021 +0800

   Windows scan code

diff --git a/plover/oslayer/winkeyboardcontrol.py b/plover/oslayer/winkeyboardcontrol.py
index ddcee37..b678801 100644
--- a/plover/oslayer/winkeyboardcontrol.py
+++ b/plover/oslayer/winkeyboardcontrol.py
@@ -26,7 +26,7 @@ from time import sleep;
from ctypes import windll, wintypes

from plover.key_combo import parse_key_combo
-from plover.oslayer.winkeyboardlayout import KeyboardLayout
+from plover.oslayer.winkeyboardlayout import KeyboardLayout, VK
from plover import log
from plover.misc import to_surrogate_pair

@@ -320,6 +320,11 @@ class KeyboardCaptureProcess(multiprocessing.Process):
        passthrough_down_keys = set()

        def on_key(pressed, event):
+            #with open('D:/log2', 'a') as f:
+            #print(event.vkCode, event.scanCode,
+                    #file=f
+                    #)
+
            if event.flags & 0x10:
                # Ignore simulated events (e.g. from KeyboardEmulation).
                return False
@@ -469,7 +474,93 @@ class KeyboardEmulation:
        if flags & KEYEVENTF_UNICODE:
            # special handling of Unicode characters
            return KEYBDINPUT(0, code, flags, 0, None)
-        return KEYBDINPUT(code, 0, flags, 0, None)
+        vkCode = code
+        scanCode = (
+{VK.BACK: 14,
+ VK.TAB: 15,
+ VK.RETURN: 28,
+ VK.CAPITAL: 58,
+ VK.ESCAPE: 1,
+ VK.SPACE: 57,
+ VK.NEXT: 81,
+ VK.END: 79,
+ VK.HOME: 71,
+ VK.LEFT: 75,
+ VK.UP: 72,
+ VK.DOWN: 80,
+ VK.SNAPSHOT: 55,
+ VK.INSERT: 82,
+ VK.DELETE: 83,
+ VK.DIGIT0: 11,
+ VK.DIGIT1: 2,
+ VK.DIGIT2: 3,
+ VK.DIGIT3: 4,
+ VK.DIGIT4: 5,
+ VK.DIGIT5: 6,
+ VK.DIGIT6: 7,
+ VK.DIGIT7: 8,
+ VK.DIGIT8: 9,
+ VK.DIGIT9: 10,
+ VK.A: 30,
+ VK.B: 48,
+ VK.C: 46,
+ VK.D: 32,
+ VK.E: 18,
+ VK.F: 33,
+ VK.G: 34,
+ VK.H: 35,
+ VK.J: 36,
+ VK.K: 37,
+ VK.L: 38,
+ VK.M: 50,
+ VK.N: 49,
+ VK.O: 24,
+ VK.P: 25,
+ VK.Q: 16,
+ VK.R: 19,
+ VK.S: 31,
+ VK.T: 20,
+ VK.U: 22,
+ VK.V: 47,
+ VK.W: 17,
+ VK.X: 45,
+ VK.Z: 44,
+ VK.LWIN: 91,
+ VK.F1: 59,
+ VK.F3: 61,
+ VK.F4: 62,
+ VK.F8: 66,
+ VK.F10: 68,
+ VK.F12: 88,
+ VK.LSHIFT: 42,
+ VK.RSHIFT: 54,
+ VK.LCONTROL: 29,
+ VK.RCONTROL: 29,
+ VK.LMENU: 56,
+ VK.RMENU: 56,
+ VK.OEM_1: 39,
+ VK.OEM_PLUS: 13,
+ VK.OEM_COMMA: 51,
+ VK.OEM_MINUS: 12,
+ VK.OEM_PERIOD: 52,
+ VK.OEM_2: 53,
+ VK.OEM_3: 41,
+ VK.OEM_4: 26,
+ VK.OEM_5: 43,
+ VK.OEM_6: 27,
+ VK.OEM_7: 40,
+
+#copy that of shift, not very meaningful
+ VK.SHIFT: 42,
+ VK.CONTROL: 29,
+ VK.MENU: 56,
+
+ 255: 99 # Fn key, send only on release?
+ }
+).get(vkCode, 0)
+        #print("*", vkCode, scanCode)
+
+        return KEYBDINPUT(vkCode, scanCode, flags, 0, None)

    # Abstraction to set flags to 0 and create an input type
    def _keyboard(self, code, flags=0):
diff --git a/plover/oslayer/winkeyboardlayout.py b/plover/oslayer/winkeyboardlayout.py
index 0ab8b05..be3f629 100644
--- a/plover/oslayer/winkeyboardlayout.py
+++ b/plover/oslayer/winkeyboardlayout.py
@@ -458,9 +458,9 @@ class KeyboardLayout: # {{{
        for ss in SHIFT_STATE:
            vk_list = []
            for mod_state, mod_vk in (
-                (SHIFT_STATE.SHIFT, VK.SHIFT),
-                (SHIFT_STATE.CTRL,  VK.CONTROL),
-                (SHIFT_STATE.MENU,  VK.MENU),
+                (SHIFT_STATE.SHIFT, VK.LSHIFT),
+                (SHIFT_STATE.CTRL,  VK.LCONTROL),
+                (SHIFT_STATE.MENU,  VK.LMENU),
            ):
                if (ss & mod_state) != 0:
                    vk_list.append(mod_vk)

user202729 avatar Oct 02 '21 14:10 user202729