Browse Source

Add different keylist support and fix shifted_keys bug

Teascade 1 year ago
parent
commit
5c7d294a19
4 changed files with 89 additions and 56 deletions
  1. 16
    56
      input_manager.py
  2. 45
    0
      keylist_linux_fi.py
  3. 27
    0
      keylist_win_fi.py
  4. 1
    0
      main.py

+ 16
- 56
input_manager.py View File

@@ -3,64 +3,19 @@ class InputManager:
3 3
 
4 4
     currently_pressed_keys = []
5 5
 
6
-    left_paw_keys = [
7
-        "1", "2", "3", "4", "5",
8
-        "Q", "W", "E", "R", "T", "Y",
9
-        "A", "S", "D", "F", "G", "H",
10
-        "Z", "X", "C", "V", "B",
6
+    left_paw_keys = []
7
+    right_paw_keys = []
8
+    shifted_keys = {}
11 9
 
12
-        "Espace", "Oem_5", "Tab", "Capital", "Lshift",
13
-        "Lcontrol", "Lwin", "Lmenu", "Space",
14
-        "F1", "F2", "F3", "F4", "F5"
15
-    ]
10
+    def init(self, linux):
11
+        if linux:
12
+            import keylist_linux_fi as keys
13
+        else:
14
+            import keylist_win_fi as keys
16 15
 
17
-    right_paw_keys = [
18
-        "6", "7", "8", "9", "0", "Oem_Plus", "Oem_4", "Back",
19
-        "U", "I", "O", "P", "Oem_6", "Oem_1", "Return",
20
-        "J", "K", "L", "Oem_3", "Oem_7", "Oem_2",
21
-        "N", "M", "Oem_Comma", "Oem_Period", "Oem_Minus", "Rshift",
22
-
23
-        "Rmenu", "Rwin", "Rcontrol",
24
-        "Up", "Left", "Down", "Right",
25
-        "Insert", "Home", "Prior", "Delete", "End", "Next",
26
-        "Snapshot", "Scroll", "Pause",
27
-        "Numpad0", "Numpad1", "Numpad2", "Numpad3", "Numpad4", "Numpad5", "Numpad6", "Numpad7", "Numpad8", "Numpad9",
28
-        "Numlock", "Divide", "Multiply", "Subtract", "Add", "Decimal",
29
-        "F6", "F7", "F8", "F9", "F10", "F11", "F12"
30
-    ]
31
-
32
-    left_paw_keys_linux_fi = [
33
-        "1", "2", "3", "4", "5",
34
-        "exclam", "quotedbl", "numbersign", "currency", "percent",
35
-        "q", "w", "e", "r", "t", "y",
36
-        "a", "s", "d", "f", "g", "h",
37
-        "z", "x", "c", "v", "b"
38
-
39
-        "Escape", "section", "Tab", "Caps_Lock", "Shift_L",
40
-        "Control_L", "Super_L", "Alt_L", "space",
41
-        "F1", "F2", "F3", "F4", "F5"
42
-    ]
43
-
44
-    right_paw_keys_linux_fi = [
45
-        "6", "7", "8", "9", "0", "plus", "[65105]", "BackSpace",
46
-        "ampersand", "slash", "parenleft", "parenright", "equal",
47
-        "u", "i", "o", "p", "aring", "[65111]", "Return",
48
-        "j", "k", "l", "odiaresis", "adiaresis", "apostrophe", "asterisk",
49
-        "n", "m", "comma", "period", "minus", "Shift_R", "semicolon", "colon", "underscore",
50
-
51
-        "[65027]", "Menu", "Control_R",
52
-        "Up", "Left", "Down", "Right",
53
-        "Insert", "Home", "Page_Up", "Delete", "End", "Next",
54
-        "Print", "Scroll_Lock", "Pause",
55
-        "P_Insert", "P_End", "P_Down", "P_Next", "P_Left", "P_Begin", "P_Right", "P_Home", "P_Up", "P_Page_Up",
56
-        "Num_Lock", "P_Divide", "P_Multiply", "P_Subtract", "P_Add", "P_Delete", "P_Enter",
57
-        "F6", "F7", "F8", "F9", "F10", "F11", "F12"
58
-    ]
59
-
60
-    pyxhook_shifted_numbers = [
61
-        "exclam", "quotedbl", "numbersign", "currency", "percent",
62
-        "ampersand", "slash", "parenleft", "parenright", "equal",
63
-    ]
16
+        self.right_paw_keys = keys.right_paw_keys
17
+        self.left_paw_keys = keys.left_paw_keys
18
+        self.shifted_keys = keys.shifted_keys
64 19
 
65 20
     def on_update(self, down):
66 21
         pass
@@ -75,6 +30,11 @@ class InputManager:
75 30
             self.currently_pressed_keys.remove(key)
76 31
             self.on_update(False)
77 32
 
33
+        shifted = self.shifted_keys.get(key)
34
+        if shifted in self.currently_pressed_keys:
35
+            self.currently_pressed_keys.remove(key)
36
+            self.on_update(False)
37
+
78 38
     def left_keys_pressed(self):
79 39
         pressed = False
80 40
         for key in self.currently_pressed_keys:

+ 45
- 0
keylist_linux_fi.py View File

@@ -0,0 +1,45 @@
1
+left_paw_keys = [
2
+    "1", "2", "3", "4", "5",
3
+    "exclam", "quotedbl", "numbersign", "currency", "percent",
4
+    "q", "w", "e", "r", "t", "y",
5
+    "a", "s", "d", "f", "g", "h",
6
+    "z", "x", "c", "v", "b"
7
+
8
+    "Escape", "section", "Tab", "Caps_Lock", "Shift_L",
9
+    "Control_L", "Super_L", "Alt_L", "space",
10
+    "F1", "F2", "F3", "F4", "F5"
11
+]
12
+
13
+right_paw_keys = [
14
+    "6", "7", "8", "9", "0", "plus", "[65105]", "BackSpace",
15
+    "ampersand", "slash", "parenleft", "parenright", "equal",
16
+    "u", "i", "o", "p", "aring", "[65111]", "Return",
17
+    "j", "k", "l", "odiaresis", "adiaresis", "apostrophe", "asterisk",
18
+    "n", "m", "comma", "period", "minus", "Shift_R", "semicolon", "colon", "underscore",
19
+
20
+    "[65027]", "Menu", "Control_R",
21
+    "Up", "Left", "Down", "Right",
22
+    "Insert", "Home", "Page_Up", "Delete", "End", "Next",
23
+    "Print", "Scroll_Lock", "Pause",
24
+    "P_Insert", "P_End", "P_Down", "P_Next", "P_Left", "P_Begin", "P_Right", "P_Home", "P_Up", "P_Page_Up",
25
+    "Num_Lock", "P_Divide", "P_Multiply", "P_Subtract", "P_Add", "P_Delete", "P_Enter",
26
+    "F6", "F7", "F8", "F9", "F10", "F11", "F12"
27
+]
28
+
29
+# pyxhook_shifted_numbers = [
30
+#    "exclam", "quotedbl", "numbersign", "currency", "percent",
31
+#    "ampersand", "slash", "parenleft", "parenright", "equal",
32
+# ]
33
+
34
+shifted_keys = {
35
+    "1": "exclam",
36
+    "2": "quotedbl",
37
+    "3": "numbersign",
38
+    "4": "currency",
39
+    "5": "percent",
40
+    "6": "ampersand",
41
+    "7": "slash",
42
+    "8": "parenleft",
43
+    "9": "parenright",
44
+    "0": "equal"
45
+}

+ 27
- 0
keylist_win_fi.py View File

@@ -0,0 +1,27 @@
1
+left_paw_keys = [
2
+    "1", "2", "3", "4", "5",
3
+    "Q", "W", "E", "R", "T", "Y",
4
+    "A", "S", "D", "F", "G", "H",
5
+    "Z", "X", "C", "V", "B",
6
+
7
+    "Espace", "Oem_5", "Tab", "Capital", "Lshift",
8
+    "Lcontrol", "Lwin", "Lmenu", "Space",
9
+    "F1", "F2", "F3", "F4", "F5"
10
+]
11
+
12
+right_paw_keys = [
13
+    "6", "7", "8", "9", "0", "Oem_Plus", "Oem_4", "Back",
14
+    "U", "I", "O", "P", "Oem_6", "Oem_1", "Return",
15
+    "J", "K", "L", "Oem_3", "Oem_7", "Oem_2",
16
+    "N", "M", "Oem_Comma", "Oem_Period", "Oem_Minus", "Rshift",
17
+
18
+    "Rmenu", "Rwin", "Rcontrol",
19
+    "Up", "Left", "Down", "Right",
20
+    "Insert", "Home", "Prior", "Delete", "End", "Next",
21
+    "Snapshot", "Scroll", "Pause",
22
+    "Numpad0", "Numpad1", "Numpad2", "Numpad3", "Numpad4", "Numpad5", "Numpad6", "Numpad7", "Numpad8", "Numpad9",
23
+    "Numlock", "Divide", "Multiply", "Subtract", "Add", "Decimal",
24
+    "F6", "F7", "F8", "F9", "F10", "F11", "F12"
25
+]
26
+
27
+shifted_keys = {}

+ 1
- 0
main.py View File

@@ -48,6 +48,7 @@ class Main:
48 48
         self.font = pygame.font.SysFont('Iosevka', 15)
49 49
         self.bongocat.load()
50 50
         self.clackmanager.load()
51
+        self.input_manager.init(linux)
51 52
 
52 53
         self.input_manager.on_update = self.update_bongocat
53 54