blob: 2866dd1d68100420872a783df8de8d58e76f8df1 [file] [log] [blame]
Christopher Plewright7b0afc12022-12-30 16:54:58 +00001" Test MS-Windows input event handling.
2" Most of this works the same in Windows GUI as well as Windows console.
Christopher Plewright20b795e2022-12-20 20:01:58 +00003
4source check.vim
5CheckMSWindows
Christopher Plewright20b795e2022-12-20 20:01:58 +00006source mouse.vim
7
Christopher Plewright7b0afc12022-12-30 16:54:58 +00008" Helper function for sending a grouped sequence of low level key presses
9" The modifer key(s) can be included as VK Key Codes in the sequence
10" Keydown events will be sent, to to the end of the group, then keyup events
11" will be sent in reverse order to release the keys.
12func SendKeyGroup(keygroup)
13 for k in a:keygroup
14 call test_mswin_event("key", {'event': "keydown", 'keycode': k})
Christopher Plewright20b795e2022-12-20 20:01:58 +000015 endfor
Christopher Plewright7b0afc12022-12-30 16:54:58 +000016 for k in reverse(copy(a:keygroup))
17 call test_mswin_event("key", {'event': "keyup", 'keycode': k})
Christopher Plewright20b795e2022-12-20 20:01:58 +000018 endfor
19endfunc
20
Christopher Plewright7b0afc12022-12-30 16:54:58 +000021" Send individual key press and release events.
Christopher Plewright20b795e2022-12-20 20:01:58 +000022" the modifers for the key press can be specified in the modifiers arg.
Christopher Plewright7b0afc12022-12-30 16:54:58 +000023func SendKeyWithModifiers(key, modifiers)
Christopher Plewright20b795e2022-12-20 20:01:58 +000024 let args = { }
25 let args.keycode = a:key
26 let args.modifiers = a:modifiers
27 let args.event = "keydown"
28 call test_mswin_event("key", args)
29 let args.event = "keyup"
30 call test_mswin_event("key", args)
31 unlet args
32endfunc
33
Christopher Plewright7b0afc12022-12-30 16:54:58 +000034" Send an individual key press, without modifiers.
35func SendKey(key)
36 call SendKeyWithModifiers(a:key, 0)
37endfunc
38
39" Send a string of individual key-press events, without modifiers.
40func SendKeyStr(keystring)
41 for k in a:keystring
42 call SendKey(k)
43 endfor
44endfunc
45
46" This tells Vim to execute the buffered keys as user commands,
47" ie. same as feekdeys with mode X would do.
48func ExecuteBufferedKeys()
49 if has('gui_running')
50 call feedkeys("\<Esc>", 'Lx!')
51 else
52 call test_mswin_event("key", {'execute': v:true})
53 endif
54endfunc
55
Christopher Plewrightc8b20492023-01-04 18:06:00 +000056" Refer to the following page for the virtual key codes:
57" https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
Christopher Plewright7b0afc12022-12-30 16:54:58 +000058let s:VK = {
59 \ 'ENTER' : 0x0D,
60 \ 'SPACE' : 0x20,
61 \ 'SHIFT' : 0x10,
62 \ 'LSHIFT' : 0xA0,
63 \ 'RSHIFT' : 0xA1,
64 \ 'CONTROL' : 0x11,
65 \ 'LCONTROL' : 0xA2,
66 \ 'RCONTROL' : 0xA3,
67 \ 'MENU' : 0x12,
68 \ 'ALT' : 0x12,
69 \ 'LMENU' : 0xA4,
70 \ 'LALT' : 0xA4,
71 \ 'RMENU' : 0xA5,
72 \ 'RALT' : 0xA5,
73 \ 'OEM_1' : 0xBA,
74 \ 'OEM_2' : 0xBF,
75 \ 'OEM_3' : 0xC0,
76 \ 'OEM_4' : 0xDB,
77 \ 'OEM_5' : 0xDC,
78 \ 'OEM_6' : 0xDD,
79 \ 'OEM_7' : 0xDE,
80 \ 'OEM_PLUS' : 0xBB,
81 \ 'OEM_COMMA' : 0xBC,
82 \ 'OEM_MINUS' : 0xBD,
83 \ 'OEM_PERIOD' : 0xBE,
84 \ 'PRIOR' : 0x21,
85 \ 'NEXT' : 0x22,
86 \ 'END' : 0x23,
87 \ 'HOME' : 0x24,
88 \ 'LEFT' : 0x25,
89 \ 'UP' : 0x26,
90 \ 'RIGHT' : 0x27,
91 \ 'DOWN' : 0x28,
92 \ 'KEY_0' : 0x30,
93 \ 'KEY_1' : 0x31,
94 \ 'KEY_2' : 0x32,
95 \ 'KEY_3' : 0x33,
96 \ 'KEY_4' : 0x34,
97 \ 'KEY_5' : 0x35,
98 \ 'KEY_6' : 0x36,
99 \ 'KEY_7' : 0x37,
100 \ 'KEY_8' : 0x38,
101 \ 'KEY_9' : 0x39,
102 \ 'KEY_A' : 0x41,
103 \ 'KEY_B' : 0x42,
104 \ 'KEY_C' : 0x43,
105 \ 'KEY_D' : 0x44,
106 \ 'KEY_E' : 0x45,
107 \ 'KEY_F' : 0x46,
108 \ 'KEY_G' : 0x47,
109 \ 'KEY_H' : 0x48,
110 \ 'KEY_I' : 0x49,
111 \ 'KEY_J' : 0x4A,
112 \ 'KEY_K' : 0x4B,
113 \ 'KEY_L' : 0x4C,
114 \ 'KEY_M' : 0x4D,
115 \ 'KEY_N' : 0x4E,
116 \ 'KEY_O' : 0x4F,
117 \ 'KEY_P' : 0x50,
118 \ 'KEY_Q' : 0x51,
119 \ 'KEY_R' : 0x52,
120 \ 'KEY_S' : 0x53,
121 \ 'KEY_T' : 0x54,
122 \ 'KEY_U' : 0x55,
123 \ 'KEY_V' : 0x56,
124 \ 'KEY_W' : 0x57,
125 \ 'KEY_X' : 0x58,
126 \ 'KEY_Y' : 0x59,
127 \ 'KEY_Z' : 0x5A,
128 \ 'NUMPAD0' : 0x60,
129 \ 'NUMPAD1' : 0x61,
130 \ 'NUMPAD2' : 0x62,
131 \ 'NUMPAD3' : 0x63,
132 \ 'NUMPAD4' : 0x64,
133 \ 'NUMPAD5' : 0x65,
134 \ 'NUMPAD6' : 0x66,
135 \ 'NUMPAD7' : 0x67,
136 \ 'NUMPAD8' : 0x68,
137 \ 'NUMPAD9' : 0x69,
138 \ 'MULTIPLY' : 0x6A,
139 \ 'ADD' : 0x6B,
140 \ 'SUBTRACT' : 0x6D,
141 \ 'F1' : 0x70,
142 \ 'F2' : 0x71,
143 \ 'F3' : 0x72,
144 \ 'F4' : 0x73,
145 \ 'F5' : 0x74,
146 \ 'F6' : 0x75,
147 \ 'F7' : 0x76,
148 \ 'F8' : 0x77,
149 \ 'F9' : 0x78,
150 \ 'F10' : 0x79,
151 \ 'F11' : 0x7A,
152 \ 'F12' : 0x7B,
153 \ 'DELETE' : 0x2E,
154 \ 'BACK' : 0x08,
155 \ 'ESCAPE' : 0x1B
156 \ }
157
158 let s:vim_MOD_MASK_SHIFT = 0x02
159 let s:vim_MOD_MASK_CTRL = 0x04
160 let s:vim_MOD_MASK_ALT = 0x08
161
162 let s:vim_key_modifiers = [
163 \ ["", 0, []],
164 \ ["S-", 2, [s:VK.SHIFT]],
165 \ ["C-", 4, [s:VK.CONTROL]],
166 \ ["C-S-", 6, [s:VK.CONTROL, s:VK.SHIFT]],
167 \ ["A-", 8, [s:VK.MENU]],
168 \ ["A-S-", 10, [s:VK.MENU, s:VK.SHIFT]],
169 \ ["A-C-", 12, [s:VK.MENU, s:VK.CONTROL]],
170 \ ["A-C-S-", 14, [s:VK.MENU, s:VK.CONTROL, s:VK.SHIFT]],
171 \]
172
173 " Assuming Standard US PC Keyboard layout
174 let s:test_ascii_key_chars = [
175 \ [[s:VK.SPACE], ' '],
176 \ [[s:VK.OEM_1], ';'],
177 \ [[s:VK.OEM_2], '/'],
178 \ [[s:VK.OEM_3], '`'],
179 \ [[s:VK.OEM_4], '['],
180 \ [[s:VK.OEM_5], '\'],
181 \ [[s:VK.OEM_6], ']'],
182 \ [[s:VK.OEM_7], ''''],
183 \ [[s:VK.OEM_PLUS], '='],
184 \ [[s:VK.OEM_COMMA], ','],
185 \ [[s:VK.OEM_MINUS], '-'],
186 \ [[s:VK.OEM_PERIOD], '.'],
187 \ [[s:VK.SHIFT, s:VK.OEM_1], ':'],
188 \ [[s:VK.SHIFT, s:VK.OEM_2], '?'],
189 \ [[s:VK.SHIFT, s:VK.OEM_3], '~'],
190 \ [[s:VK.SHIFT, s:VK.OEM_4], '{'],
191 \ [[s:VK.SHIFT, s:VK.OEM_5], '|'],
192 \ [[s:VK.SHIFT, s:VK.OEM_6], '}'],
193 \ [[s:VK.SHIFT, s:VK.OEM_7], '"'],
194 \ [[s:VK.SHIFT, s:VK.OEM_PLUS], '+'],
195 \ [[s:VK.SHIFT, s:VK.OEM_COMMA], '<'],
196 \ [[s:VK.SHIFT, s:VK.OEM_MINUS], '_'],
197 \ [[s:VK.SHIFT, s:VK.OEM_PERIOD], '>'],
198 \ [[s:VK.KEY_1], '1'],
199 \ [[s:VK.KEY_2], '2'],
200 \ [[s:VK.KEY_3], '3'],
201 \ [[s:VK.KEY_4], '4'],
202 \ [[s:VK.KEY_5], '5'],
203 \ [[s:VK.KEY_6], '6'],
204 \ [[s:VK.KEY_7], '7'],
205 \ [[s:VK.KEY_8], '8'],
206 \ [[s:VK.KEY_9], '9'],
207 \ [[s:VK.KEY_0], '0'],
208 \ [[s:VK.SHIFT, s:VK.KEY_1], '!'],
209 \ [[s:VK.SHIFT, s:VK.KEY_2], '@'],
210 \ [[s:VK.SHIFT, s:VK.KEY_3], '#'],
211 \ [[s:VK.SHIFT, s:VK.KEY_4], '$'],
212 \ [[s:VK.SHIFT, s:VK.KEY_5], '%'],
213 \ [[s:VK.SHIFT, s:VK.KEY_6], '^'],
214 \ [[s:VK.SHIFT, s:VK.KEY_7], '&'],
215 \ [[s:VK.SHIFT, s:VK.KEY_8], '*'],
216 \ [[s:VK.SHIFT, s:VK.KEY_9], '('],
217 \ [[s:VK.SHIFT, s:VK.KEY_0], ')'],
218 \ [[s:VK.KEY_A], 'a'],
219 \ [[s:VK.KEY_B], 'b'],
220 \ [[s:VK.KEY_C], 'c'],
221 \ [[s:VK.KEY_D], 'd'],
222 \ [[s:VK.KEY_E], 'e'],
223 \ [[s:VK.KEY_F], 'f'],
224 \ [[s:VK.KEY_G], 'g'],
225 \ [[s:VK.KEY_H], 'h'],
226 \ [[s:VK.KEY_I], 'i'],
227 \ [[s:VK.KEY_J], 'j'],
228 \ [[s:VK.KEY_K], 'k'],
229 \ [[s:VK.KEY_L], 'l'],
230 \ [[s:VK.KEY_M], 'm'],
231 \ [[s:VK.KEY_N], 'n'],
232 \ [[s:VK.KEY_O], 'o'],
233 \ [[s:VK.KEY_P], 'p'],
234 \ [[s:VK.KEY_Q], 'q'],
235 \ [[s:VK.KEY_R], 'r'],
236 \ [[s:VK.KEY_S], 's'],
237 \ [[s:VK.KEY_T], 't'],
238 \ [[s:VK.KEY_U], 'u'],
239 \ [[s:VK.KEY_V], 'v'],
240 \ [[s:VK.KEY_W], 'w'],
241 \ [[s:VK.KEY_X], 'x'],
242 \ [[s:VK.KEY_Y], 'y'],
243 \ [[s:VK.KEY_Z], 'z'],
244 \ [[s:VK.SHIFT, s:VK.KEY_A], 'A'],
245 \ [[s:VK.SHIFT, s:VK.KEY_B], 'B'],
246 \ [[s:VK.SHIFT, s:VK.KEY_C], 'C'],
247 \ [[s:VK.SHIFT, s:VK.KEY_D], 'D'],
248 \ [[s:VK.SHIFT, s:VK.KEY_E], 'E'],
249 \ [[s:VK.SHIFT, s:VK.KEY_F], 'F'],
250 \ [[s:VK.SHIFT, s:VK.KEY_G], 'G'],
251 \ [[s:VK.SHIFT, s:VK.KEY_H], 'H'],
252 \ [[s:VK.SHIFT, s:VK.KEY_I], 'I'],
253 \ [[s:VK.SHIFT, s:VK.KEY_J], 'J'],
254 \ [[s:VK.SHIFT, s:VK.KEY_K], 'K'],
255 \ [[s:VK.SHIFT, s:VK.KEY_L], 'L'],
256 \ [[s:VK.SHIFT, s:VK.KEY_M], 'M'],
257 \ [[s:VK.SHIFT, s:VK.KEY_N], 'N'],
258 \ [[s:VK.SHIFT, s:VK.KEY_O], 'O'],
259 \ [[s:VK.SHIFT, s:VK.KEY_P], 'P'],
260 \ [[s:VK.SHIFT, s:VK.KEY_Q], 'Q'],
261 \ [[s:VK.SHIFT, s:VK.KEY_R], 'R'],
262 \ [[s:VK.SHIFT, s:VK.KEY_S], 'S'],
263 \ [[s:VK.SHIFT, s:VK.KEY_T], 'T'],
264 \ [[s:VK.SHIFT, s:VK.KEY_U], 'U'],
265 \ [[s:VK.SHIFT, s:VK.KEY_V], 'V'],
266 \ [[s:VK.SHIFT, s:VK.KEY_W], 'W'],
267 \ [[s:VK.SHIFT, s:VK.KEY_X], 'X'],
268 \ [[s:VK.SHIFT, s:VK.KEY_Y], 'Y'],
269 \ [[s:VK.SHIFT, s:VK.KEY_Z], 'Z'],
270 \ [[s:VK.CONTROL, s:VK.KEY_A], 0x01],
271 \ [[s:VK.CONTROL, s:VK.KEY_B], 0x02],
272 \ [[s:VK.CONTROL, s:VK.KEY_C], 0x03],
273 \ [[s:VK.CONTROL, s:VK.KEY_D], 0x04],
274 \ [[s:VK.CONTROL, s:VK.KEY_E], 0x05],
275 \ [[s:VK.CONTROL, s:VK.KEY_F], 0x06],
276 \ [[s:VK.CONTROL, s:VK.KEY_G], 0x07],
277 \ [[s:VK.CONTROL, s:VK.KEY_H], 0x08],
278 \ [[s:VK.CONTROL, s:VK.KEY_I], 0x09],
279 \ [[s:VK.CONTROL, s:VK.KEY_J], 0x0A],
280 \ [[s:VK.CONTROL, s:VK.KEY_K], 0x0B],
281 \ [[s:VK.CONTROL, s:VK.KEY_L], 0x0C],
282 \ [[s:VK.CONTROL, s:VK.KEY_M], 0x0D],
283 \ [[s:VK.CONTROL, s:VK.KEY_N], 0x0E],
284 \ [[s:VK.CONTROL, s:VK.KEY_O], 0x0F],
285 \ [[s:VK.CONTROL, s:VK.KEY_P], 0x10],
286 \ [[s:VK.CONTROL, s:VK.KEY_Q], 0x11],
287 \ [[s:VK.CONTROL, s:VK.KEY_R], 0x12],
288 \ [[s:VK.CONTROL, s:VK.KEY_S], 0x13],
289 \ [[s:VK.CONTROL, s:VK.KEY_T], 0x14],
290 \ [[s:VK.CONTROL, s:VK.KEY_U], 0x15],
291 \ [[s:VK.CONTROL, s:VK.KEY_V], 0x16],
292 \ [[s:VK.CONTROL, s:VK.KEY_W], 0x17],
293 \ [[s:VK.CONTROL, s:VK.KEY_X], 0x18],
294 \ [[s:VK.CONTROL, s:VK.KEY_Y], 0x19],
295 \ [[s:VK.CONTROL, s:VK.KEY_Z], 0x1A],
296 \ [[s:VK.CONTROL, s:VK.OEM_4], 0x1B],
297 \ [[s:VK.CONTROL, s:VK.OEM_5], 0x1C],
298 \ [[s:VK.CONTROL, s:VK.OEM_6], 0x1D],
Christopher Plewrightc8b20492023-01-04 18:06:00 +0000299 \ [[s:VK.CONTROL, s:VK.KEY_6], 0x1E],
300 \ [[s:VK.CONTROL, s:VK.OEM_MINUS], 0x1F],
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000301 \ ]
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000302
303let s:test_extra_key_chars = [
304 \ [[s:VK.ALT, s:VK.KEY_1], '±'],
305 \ [[s:VK.ALT, s:VK.KEY_2], '²'],
306 \ [[s:VK.ALT, s:VK.KEY_3], '³'],
307 \ [[s:VK.ALT, s:VK.KEY_4], '´'],
308 \ [[s:VK.ALT, s:VK.KEY_5], 'µ'],
309 \ [[s:VK.ALT, s:VK.KEY_6], '¶'],
310 \ [[s:VK.ALT, s:VK.KEY_7], '·'],
311 \ [[s:VK.ALT, s:VK.KEY_8], '¸'],
312 \ [[s:VK.ALT, s:VK.KEY_9], '¹'],
313 \ [[s:VK.ALT, s:VK.KEY_0], '°'],
314 \ [[s:VK.ALT, s:VK.KEY_A], 'á'],
315 \ [[s:VK.ALT, s:VK.KEY_B], 'â'],
316 \ [[s:VK.ALT, s:VK.KEY_C], 'ã'],
317 \ [[s:VK.ALT, s:VK.KEY_D], 'ä'],
318 \ [[s:VK.ALT, s:VK.KEY_E], 'Ã¥'],
319 \ [[s:VK.ALT, s:VK.KEY_F], 'æ'],
320 \ [[s:VK.ALT, s:VK.KEY_G], 'ç'],
321 \ [[s:VK.ALT, s:VK.KEY_H], 'è'],
322 \ [[s:VK.ALT, s:VK.KEY_I], 'é'],
323 \ [[s:VK.ALT, s:VK.KEY_J], 'ê'],
324 \ [[s:VK.ALT, s:VK.KEY_K], 'ë'],
325 \ [[s:VK.ALT, s:VK.KEY_L], 'ì'],
326 \ [[s:VK.ALT, s:VK.KEY_M], 'í'],
327 \ [[s:VK.ALT, s:VK.KEY_N], 'î'],
328 \ [[s:VK.ALT, s:VK.KEY_O], 'ï'],
329 \ [[s:VK.ALT, s:VK.KEY_P], 'ð'],
330 \ [[s:VK.ALT, s:VK.KEY_Q], 'ñ'],
331 \ [[s:VK.ALT, s:VK.KEY_R], 'ò'],
332 \ [[s:VK.ALT, s:VK.KEY_S], 'ó'],
333 \ [[s:VK.ALT, s:VK.KEY_T], 'ô'],
334 \ [[s:VK.ALT, s:VK.KEY_U], 'õ'],
335 \ [[s:VK.ALT, s:VK.KEY_V], 'ö'],
336 \ [[s:VK.ALT, s:VK.KEY_W], '÷'],
337 \ [[s:VK.ALT, s:VK.KEY_X], 'ø'],
338 \ [[s:VK.ALT, s:VK.KEY_Y], 'ù'],
339 \ [[s:VK.ALT, s:VK.KEY_Z], 'ú'],
340 \ ]
341
342func s:LoopTestKeyArray(arr)
Christopher Plewrightc8b20492023-01-04 18:06:00 +0000343 " flush out anything in the typeahead buffer
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000344 while getchar(0)
345 endwhile
346
347 for [kcodes, kstr] in a:arr
348 " Send as a sequence of key presses.
349 call SendKeyGroup(kcodes)
350 let ch = getcharstr(0)
351 " need to deal a bit differently with the non-printable ascii chars < 0x20
Christopher Plewrightc8b20492023-01-04 18:06:00 +0000352 if kstr < 0x20 && index([s:VK.CONTROL, s:VK.LCONTROL, s:VK.RCONTROL], kcodes[0]) >= 0
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000353 call assert_equal(nr2char(kstr), $"{ch}")
354 else
355 call assert_equal(kstr, $"{ch}")
356 endif
357 let mod_mask = getcharmod()
358 " the mod_mask is zero when no modifiers are used
359 " and when the virtual termcap maps the character
360 call assert_equal(0, mod_mask, $"key = {kstr}")
361
362 " Send as a single key press with a modifers mask.
363 let modifiers = 0
364 let key = kcodes[0]
365 for key in kcodes
366 if index([s:VK.SHIFT, s:VK.LSHIFT, s:VK.RSHIFT], key) >= 0
367 let modifiers = modifiers + s:vim_MOD_MASK_SHIFT
368 endif
369 if index([s:VK.CONTROL, s:VK.LCONTROL, s:VK.RCONTROL], key) >= 0
370 let modifiers = modifiers + s:vim_MOD_MASK_CTRL
371 endif
372 if index([s:VK.ALT, s:VK.LALT, s:VK.RALT], key) >= 0
373 let modifiers = modifiers + s:vim_MOD_MASK_ALT
374 endif
375 endfor
376 call SendKeyWithModifiers(key, modifiers)
377 let ch = getcharstr(0)
378 " need to deal a bit differently with the non-printable ascii chars < 0x20
379 if kstr < 0x20 && index([s:VK.CONTROL, s:VK.LCONTROL, s:VK.RCONTROL], kcodes[0]) >= 0
380 call assert_equal(nr2char(kstr), $"{ch}")
381 else
382 call assert_equal(kstr, $"{ch}")
383 endif
384 let mod_mask = getcharmod()
385 " the mod_mask is zero when no modifiers are used
386 " and when the virtual termcap maps the character
387 call assert_equal(0, mod_mask, $"key = {kstr}")
388 endfor
389
Christopher Plewrightc8b20492023-01-04 18:06:00 +0000390 " flush out anything in the typeahead buffer
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000391 while getchar(0)
392 endwhile
393
394endfunc
395
396" Test MS-Windows key events
Christopher Plewright20b795e2022-12-20 20:01:58 +0000397func Test_mswin_key_event()
398 CheckMSWindows
399 new
400
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000401 call s:LoopTestKeyArray(s:test_ascii_key_chars)
Christopher Plewright20b795e2022-12-20 20:01:58 +0000402
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000403 if !has('gui_running')
404 call s:LoopTestKeyArray(s:test_extra_key_chars)
405 endif
Christopher Plewright20b795e2022-12-20 20:01:58 +0000406
407" Test keyboard codes for digits
408" (0x30 - 0x39) : VK_0 - VK_9 are the same as ASCII '0' - '9'
409 for kc in range(48, 57)
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000410 call SendKey(kc)
Christopher Plewright20b795e2022-12-20 20:01:58 +0000411 let ch = getcharstr(0)
412 call assert_equal(nr2char(kc), ch)
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000413 call SendKeyWithModifiers(kc, 0)
Christopher Plewright20b795e2022-12-20 20:01:58 +0000414 let ch = getcharstr(0)
415 call assert_equal(nr2char(kc), ch)
416 endfor
417
418" Test keyboard codes for Alt-0 to Alt-9
419" Expect +128 from the digit char codes
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000420 for modkey in [s:VK.ALT, s:VK.LALT, s:VK.RALT]
Christopher Plewright20b795e2022-12-20 20:01:58 +0000421 for kc in range(48, 57)
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000422 call SendKeyGroup([modkey, kc])
Christopher Plewright20b795e2022-12-20 20:01:58 +0000423 let ch = getchar(0)
424 call assert_equal(kc+128, ch)
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000425 call SendKeyWithModifiers(kc, s:vim_MOD_MASK_ALT)
Christopher Plewright20b795e2022-12-20 20:01:58 +0000426 let ch = getchar(0)
427 call assert_equal(kc+128, ch)
428 endfor
429 endfor
430
431" Test for lowercase 'a' to 'z', VK codes 65(0x41) - 90(0x5A)
432" Note: VK_A-VK_Z virtual key codes coincide with uppercase ASCII codes A-Z.
433" eg VK_A is 65, and the ASCII character code for uppercase 'A' is also 65.
434" Caution: these are interpreted as lowercase when Shift is NOT pressed.
435" eg, sending VK_A (65) 'A' Key code without shift modifier, will produce ASCII
436" char 'a' (91) as the output. The ASCII codes for the lowercase letters are
437" numbered 32 higher than their uppercase versions.
438 for kc in range(65, 90)
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000439 call SendKey(kc)
Christopher Plewright20b795e2022-12-20 20:01:58 +0000440 let ch = getcharstr(0)
441 call assert_equal(nr2char(kc + 32), ch)
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000442 call SendKeyWithModifiers(kc, 0)
Christopher Plewright20b795e2022-12-20 20:01:58 +0000443 let ch = getcharstr(0)
444 call assert_equal(nr2char(kc + 32), ch)
445 endfor
446
447" Test for Uppercase 'A' - 'Z' keys
448" ie. with VK_SHIFT, expect the keycode = character code.
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000449 for modkey in [s:VK.SHIFT, s:VK.LSHIFT, s:VK.RSHIFT]
450 for kc in range(65, 90)
451 call SendKeyGroup([modkey, kc])
452 let ch = getcharstr(0)
453 call assert_equal(nr2char(kc), ch)
454 call SendKeyWithModifiers(kc, s:vim_MOD_MASK_SHIFT)
455 let ch = getcharstr(0)
456 call assert_equal(nr2char(kc), ch)
457 endfor
Christopher Plewright20b795e2022-12-20 20:01:58 +0000458 endfor
459
460 " Test for <Ctrl-A> to <Ctrl-Z> keys
Christopher Plewright20b795e2022-12-20 20:01:58 +0000461 " Expect the unicode characters 0x01 to 0x1A
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000462 for modkey in [s:VK.CONTROL, s:VK.LCONTROL, s:VK.RCONTROL]
Christopher Plewright20b795e2022-12-20 20:01:58 +0000463 for kc in range(65, 90)
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000464 call SendKeyGroup([modkey, kc])
Christopher Plewright20b795e2022-12-20 20:01:58 +0000465 let ch = getcharstr(0)
466 call assert_equal(nr2char(kc - 64), ch)
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000467 call SendKeyWithModifiers(kc, s:vim_MOD_MASK_CTRL)
Christopher Plewright20b795e2022-12-20 20:01:58 +0000468 let ch = getcharstr(0)
469 call assert_equal(nr2char(kc - 64), ch)
470 endfor
471 endfor
472
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000473 " Windows intercepts some of these keys in the GUI.
Christopher Plewright20b795e2022-12-20 20:01:58 +0000474 if !has("gui_running")
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000475 " Test for <Alt-A> to <Alt-Z> keys
Christopher Plewright20b795e2022-12-20 20:01:58 +0000476 " Expect the unicode characters 0xE1 to 0xFA
477 " ie. 160 higher than the lowercase equivalent
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000478 for modkey in [s:VK.ALT, s:VK.LALT, s:VK.RALT]
479 for kc in range(65, 90)
480 call SendKeyGroup([modkey, kc])
481 let ch = getchar(0)
482 call assert_equal(kc+160, ch)
483 call SendKeyWithModifiers(kc, s:vim_MOD_MASK_ALT)
484 let ch = getchar(0)
485 call assert_equal(kc+160, ch)
486 endfor
Christopher Plewright20b795e2022-12-20 20:01:58 +0000487 endfor
488 endif
489
Christopher Plewrightc8b20492023-01-04 18:06:00 +0000490 " Test for Function Keys 'F1' to 'F12'
491 " VK codes 112(0x70) - 123(0x7B)
492 " Also with ALL permutatios of modifiers; Shift, Ctrl & Alt
493 " NOTE: Windows intercepts some of these keys in the GUI
Christopher Plewright20b795e2022-12-20 20:01:58 +0000494 if !has("gui_running")
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000495 for [mod_str, vim_mod_mask, mod_keycodes] in s:vim_key_modifiers
496 for n in range(1, 12)
497 let kstr = $"{mod_str}F{n}"
498 let keycode = eval('"\<' .. kstr .. '>"')
Christopher Plewrightc8b20492023-01-04 18:06:00 +0000499 " flush out anything in the typeahead buffer
500 while getchar(0)
501 endwhile
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000502 " call SendKeyGroup(mod_keycodes + [111+n])
503 call SendKeyWithModifiers(111+n, vim_mod_mask)
504 let ch = getcharstr(0)
505 let mod_mask = getcharmod()
Christopher Plewrightc8b20492023-01-04 18:06:00 +0000506 call assert_equal(keycode, $"{ch}", $"key = {kstr}")
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000507 " workaround for the virtual termcap maps changing the character instead
508 " of sending Shift
509 for mod_key in mod_keycodes
510 if index([s:VK.SHIFT, s:VK.LSHIFT, s:VK.RSHIFT], mod_key) >= 0
511 let mod_mask = mod_mask + s:vim_MOD_MASK_SHIFT
512 endif
513 endfor
Christopher Plewrightc8b20492023-01-04 18:06:00 +0000514 call assert_equal(vim_mod_mask, mod_mask, $"mod = {vim_mod_mask} for key = {kstr}")
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000515 endfor
516 endfor
Christopher Plewright20b795e2022-12-20 20:01:58 +0000517 endif
518
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000519 " Test for the various Ctrl and Shift key combinations.
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000520 let keytests = [
521 \ [[s:VK.SHIFT, s:VK.PRIOR], "S-Pageup", 2],
522 \ [[s:VK.LSHIFT, s:VK.PRIOR], "S-Pageup", 2],
523 \ [[s:VK.RSHIFT, s:VK.PRIOR], "S-Pageup", 2],
524 \ [[s:VK.CONTROL, s:VK.PRIOR], "C-Pageup", 4],
525 \ [[s:VK.LCONTROL, s:VK.PRIOR], "C-Pageup", 4],
526 \ [[s:VK.RCONTROL, s:VK.PRIOR], "C-Pageup", 4],
527 \ [[s:VK.CONTROL, s:VK.SHIFT, s:VK.PRIOR], "C-S-Pageup", 6],
528 \ [[s:VK.SHIFT, s:VK.NEXT], "S-PageDown", 2],
529 \ [[s:VK.LSHIFT, s:VK.NEXT], "S-PageDown", 2],
530 \ [[s:VK.RSHIFT, s:VK.NEXT], "S-PageDown", 2],
531 \ [[s:VK.CONTROL, s:VK.NEXT], "C-PageDown", 4],
532 \ [[s:VK.LCONTROL, s:VK.NEXT], "C-PageDown", 4],
533 \ [[s:VK.RCONTROL, s:VK.NEXT], "C-PageDown", 4],
534 \ [[s:VK.CONTROL, s:VK.SHIFT, s:VK.NEXT], "C-S-PageDown", 6],
535 \ [[s:VK.SHIFT, s:VK.END], "S-End", 0],
536 \ [[s:VK.CONTROL, s:VK.END], "C-End", 0],
537 \ [[s:VK.CONTROL, s:VK.SHIFT, s:VK.END], "C-S-End", 4],
538 \ [[s:VK.SHIFT, s:VK.HOME], "S-Home", 0],
539 \ [[s:VK.CONTROL, s:VK.HOME], "C-Home", 0],
540 \ [[s:VK.CONTROL, s:VK.SHIFT, s:VK.HOME], "C-S-Home", 4],
541 \ [[s:VK.SHIFT, s:VK.LEFT], "S-Left", 0],
542 \ [[s:VK.CONTROL, s:VK.LEFT], "C-Left", 0],
543 \ [[s:VK.CONTROL, s:VK.SHIFT, s:VK.LEFT], "C-S-Left", 4],
544 \ [[s:VK.SHIFT, s:VK.UP], "S-Up", 0],
545 \ [[s:VK.CONTROL, s:VK.UP], "C-Up", 4],
546 \ [[s:VK.CONTROL, s:VK.SHIFT, s:VK.UP], "C-S-Up", 4],
547 \ [[s:VK.SHIFT, s:VK.RIGHT], "S-Right", 0],
548 \ [[s:VK.CONTROL, s:VK.RIGHT], "C-Right", 0],
549 \ [[s:VK.CONTROL, s:VK.SHIFT, s:VK.RIGHT], "C-S-Right", 4],
550 \ [[s:VK.SHIFT, s:VK.DOWN], "S-Down", 0],
551 \ [[s:VK.CONTROL, s:VK.DOWN], "C-Down", 4],
552 \ [[s:VK.CONTROL, s:VK.SHIFT, s:VK.DOWN], "C-S-Down", 4],
553 \ [[s:VK.CONTROL, s:VK.KEY_0], "C-0", 4],
554 \ [[s:VK.CONTROL, s:VK.KEY_1], "C-1", 4],
555 \ [[s:VK.CONTROL, s:VK.KEY_2], "C-@", 0],
556 \ [[s:VK.CONTROL, s:VK.KEY_3], "C-3", 4],
557 \ [[s:VK.CONTROL, s:VK.KEY_4], "C-4", 4],
558 \ [[s:VK.CONTROL, s:VK.KEY_5], "C-5", 4],
559 \ [[s:VK.CONTROL, s:VK.KEY_6], "C-^", 0],
560 \ [[s:VK.CONTROL, s:VK.KEY_7], "C-7", 4],
561 \ [[s:VK.CONTROL, s:VK.KEY_8], "C-8", 4],
562 \ [[s:VK.CONTROL, s:VK.KEY_9], "C-9", 4],
563 \ [[s:VK.CONTROL, s:VK.NUMPAD0], "C-0", 4],
564 \ [[s:VK.CONTROL, s:VK.NUMPAD1], "C-1", 4],
565 \ [[s:VK.CONTROL, s:VK.NUMPAD2], "C-2", 4],
566 \ [[s:VK.CONTROL, s:VK.NUMPAD3], "C-3", 4],
567 \ [[s:VK.CONTROL, s:VK.NUMPAD4], "C-4", 4],
568 \ [[s:VK.CONTROL, s:VK.NUMPAD5], "C-5", 4],
569 \ [[s:VK.CONTROL, s:VK.NUMPAD6], "C-6", 4],
570 \ [[s:VK.CONTROL, s:VK.NUMPAD7], "C-7", 4],
571 \ [[s:VK.CONTROL, s:VK.NUMPAD8], "C-8", 4],
572 \ [[s:VK.CONTROL, s:VK.NUMPAD9], "C-9", 4],
573 \ [[s:VK.CONTROL, s:VK.MULTIPLY], "C-*", 4],
574 \ [[s:VK.CONTROL, s:VK.ADD], "C-+", 4],
575 \ [[s:VK.CONTROL, s:VK.SUBTRACT], "C--", 4],
576 \ [[s:VK.CONTROL, s:VK.OEM_MINUS], "C-_", 0]
577 \ ]
578
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000579 for [kcodes, kstr, kmod] in keytests
580 call SendKeyGroup(kcodes)
581 let ch = getcharstr(0)
582 let mod = getcharmod()
583 let keycode = eval('"\<' .. kstr .. '>"')
Christopher Plewrightc8b20492023-01-04 18:06:00 +0000584 call assert_equal(keycode, ch, $"key = {kstr}")
585 call assert_equal(kmod, mod, $"mod = {kmod} key = {kstr}")
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000586 endfor
587
Christopher Plewright20b795e2022-12-20 20:01:58 +0000588 bw!
589endfunc
590
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000591
592" Test for QWERTY Ctrl+- which should result in ^_
593" issue #10817
594func Test_QWERTY_Ctrl_minus()
595 CheckMSWindows
596 new
597
598 call SendKeyGroup([s:VK.CONTROL, s:VK.OEM_MINUS])
599 let ch = getcharstr(0)
600 call assert_equal(nr2char(0x1f),ch)
601
602 call SendKey(s:VK.KEY_I)
603 call SendKeyGroup([s:VK.CONTROL, s:VK.SUBTRACT])
604 call SendKey(s:VK.ESCAPE)
605 call ExecuteBufferedKeys()
606 call assert_equal('-', getline('$'))
607
608 %d _
609 imapclear
610 imap <C-_> BINGO
611 call SendKey(s:VK.KEY_I)
612 call SendKeyGroup([s:VK.CONTROL, s:VK.OEM_MINUS])
613 call SendKey(s:VK.ESCAPE)
614 call ExecuteBufferedKeys()
615 call assert_equal('BINGO', getline('$'))
616
617 %d _
618 imapclear
619 exec "imap \x1f BILBO"
620 call SendKey(s:VK.KEY_I)
621 call SendKeyGroup([s:VK.CONTROL, s:VK.OEM_MINUS])
622 call SendKey(s:VK.ESCAPE)
623 call ExecuteBufferedKeys()
624 call assert_equal('BILBO', getline('$'))
625
Christopher Plewright7b0afc12022-12-30 16:54:58 +0000626 imapclear
627 bw!
628endfunc
629
630" Test MS-Windows mouse events
Christopher Plewright20b795e2022-12-20 20:01:58 +0000631func Test_mswin_mouse_event()
632 CheckMSWindows
633 new
634
635 set mousemodel=extend
636 call test_override('no_query_mouse', 1)
637 call WaitForResponses()
638
639 let msg = ''
640
641 call setline(1, ['one two three', 'four five six'])
642
643 " Test mouse movement
644 " by default, no mouse move events are generated
645 " this setting enables it to generate move events
646 set mousemev
647
648 if !has('gui_running')
649 " console version needs a button pressed,
650 " otherwise it ignores mouse movements.
651 call MouseLeftClick(2, 3)
652 endif
653 call MSWinMouseEvent(0x700, 8, 13, 0, 0, 0)
654 if has('gui_running')
655 call feedkeys("\<Esc>", 'Lx!')
656 endif
657 let pos = getmousepos()
658 call assert_equal(8, pos.screenrow)
659 call assert_equal(13, pos.screencol)
660
661 if !has('gui_running')
662 call MouseLeftClick(2, 3)
663 call MSWinMouseEvent(0x700, 6, 4, 1, 0, 0)
664 let pos = getmousepos()
665 call assert_equal(6, pos.screenrow)
666 call assert_equal(4, pos.screencol)
667 endif
668
669 " test cells vs pixels
670 if has('gui_running')
671 let args = { }
672 let args.row = 9
673 let args.col = 7
674 let args.move = 1
675 let args.cell = 1
676 call test_mswin_event("mouse", args)
677 call feedkeys("\<Esc>", 'Lx!')
678 let pos = getmousepos()
679 call assert_equal(9, pos.screenrow)
680 call assert_equal(7, pos.screencol)
681
682 let args.cell = 0
683 call test_mswin_event("mouse", args)
684 call feedkeys("\<Esc>", 'Lx!')
685 let pos = getmousepos()
686 call assert_equal(1, pos.screenrow)
687 call assert_equal(1, pos.screencol)
688
689 unlet args
690 endif
691
692 " finish testing mouse movement
693 set mousemev&
694
695 " place the cursor using left click and release in normal mode
696 call MouseLeftClick(2, 4)
697 call MouseLeftRelease(2, 4)
698 if has('gui_running')
699 call feedkeys("\<Esc>", 'Lx!')
700 endif
701 call assert_equal([0, 2, 4, 0], getpos('.'))
702
703 " select and yank a word
704 let @" = ''
705 call MouseLeftClick(1, 9)
706 let args = #{button: 0, row: 1, col: 9, multiclick: 1, modifiers: 0}
707 call test_mswin_event('mouse', args)
708 call MouseLeftRelease(1, 9)
709 call feedkeys("y", 'Lx!')
710 call assert_equal('three', @")
711
712 " create visual selection using right click
713 let @" = ''
714
715 call MouseLeftClick(2 ,6)
716 call MouseLeftRelease(2, 6)
717 call MouseRightClick(2, 13)
718 call MouseRightRelease(2, 13)
719 call feedkeys("y", 'Lx!')
720 call assert_equal('five six', @")
721
722 " paste using middle mouse button
723 let @* = 'abc '
724 call feedkeys('""', 'Lx!')
725 call MouseMiddleClick(1, 9)
726 call MouseMiddleRelease(1, 9)
727 if has('gui_running')
728 call feedkeys("\<Esc>", 'Lx!')
729 endif
730 call assert_equal(['one two abc three', 'four five six'], getline(1, '$'))
731
732 " test mouse scrolling (aka touchpad scrolling.)
733 %d _
734 set scrolloff=0
735 call setline(1, range(1, 100))
736
737 " Scroll Down
738 call MouseWheelDown(2, 1)
739 call MouseWheelDown(2, 1)
740 call MouseWheelDown(2, 1)
741 call feedkeys("H", 'Lx!')
742 call assert_equal(10, line('.'))
743
744 " Scroll Up
745 call MouseWheelUp(2, 1)
746 call MouseWheelUp(2, 1)
747 call feedkeys("H", 'Lx!')
748 call assert_equal(4, line('.'))
749
750 " Shift Scroll Down
751 call MouseShiftWheelDown(2, 1)
752 call feedkeys("H", 'Lx!')
753 " should scroll from where it is (4) + visible buffer height - cmdheight
754 let shift_scroll_height = line('w$') - line('w0') - &cmdheight
755 call assert_equal(4 + shift_scroll_height, line('.'))
756
757 " Shift Scroll Up
758 call MouseShiftWheelUp(2, 1)
759 call feedkeys("H", 'Lx!')
760 call assert_equal(4, line('.'))
761
762 if !has('gui_running')
763 " Shift Scroll Down (using MOD)
764 call MSWinMouseEvent(0x100, 2, 1, 0, 0, 0x04)
765 call feedkeys("H", 'Lx!')
766 " should scroll from where it is (4) + visible buffer height - cmdheight
767 let shift_scroll_height = line('w$') - line('w0') - &cmdheight
768 call assert_equal(4 + shift_scroll_height, line('.'))
769
770 " Shift Scroll Up (using MOD)
771 call MSWinMouseEvent(0x200, 2, 1, 0, 0, 0x04)
772 call feedkeys("H", 'Lx!')
773 call assert_equal(4, line('.'))
774 endif
775
776 set scrolloff&
777
778 %d _
779 set nowrap
780 " make the buffer 500 wide.
781 call setline(1, range(10)->join('')->repeat(50))
782 " Scroll Right
783 call MouseWheelRight(1, 5)
784 call MouseWheelRight(1, 10)
785 call MouseWheelRight(1, 15)
786 call feedkeys('g0', 'Lx!')
787 call assert_equal(19, col('.'))
788
789 " Scroll Left
790 call MouseWheelLeft(1, 15)
791 call MouseWheelLeft(1, 10)
792 call feedkeys('g0', 'Lx!')
793 call assert_equal(7, col('.'))
794
795 " Shift Scroll Right
796 call MouseShiftWheelRight(1, 10)
797 call feedkeys('g0', 'Lx!')
798 " should scroll from where it is (7) + window width
799 call assert_equal(7 + winwidth(0), col('.'))
800
801 " Shift Scroll Left
802 call MouseShiftWheelLeft(1, 50)
803 call feedkeys('g0', 'Lx!')
804 call assert_equal(7, col('.'))
805 set wrap&
806
807 %d _
808 call setline(1, repeat([repeat('a', 60)], 10))
809
810 " record various mouse events
811 let mouseEventNames = [
812 \ 'LeftMouse', 'LeftRelease', '2-LeftMouse', '3-LeftMouse',
813 \ 'S-LeftMouse', 'A-LeftMouse', 'C-LeftMouse', 'MiddleMouse',
814 \ 'MiddleRelease', '2-MiddleMouse', '3-MiddleMouse',
815 \ 'S-MiddleMouse', 'A-MiddleMouse', 'C-MiddleMouse',
816 \ 'RightMouse', 'RightRelease', '2-RightMouse',
817 \ '3-RightMouse', 'S-RightMouse', 'A-RightMouse', 'C-RightMouse',
818 \ ]
819 let mouseEventCodes = map(copy(mouseEventNames), "'<' .. v:val .. '>'")
820 let g:events = []
821 for e in mouseEventCodes
822 exe 'nnoremap ' .. e .. ' <Cmd>call add(g:events, "' ..
823 \ substitute(e, '[<>]', '', 'g') .. '")<CR>'
824 endfor
825
826 " Test various mouse buttons
827 "(0 - Left, 1 - Middle, 2 - Right,
828 " 0x300 - MOUSE_X1/FROM_LEFT_3RD_BUTTON,
829 " 0x400 - MOUSE_X2/FROM_LEFT_4TH_BUTTON)
830 for button in [0, 1, 2, 0x300, 0x400]
831 " Single click
832 let args = #{button: button, row: 2, col: 5, multiclick: 0, modifiers: 0}
833 call test_mswin_event('mouse', args)
834 let args.button = 3
835 call test_mswin_event('mouse', args)
836
837 " Double Click
838 let args.button = button
839 call test_mswin_event('mouse', args)
840 let args.multiclick = 1
841 call test_mswin_event('mouse', args)
842 let args.button = 3
843 let args.multiclick = 0
844 call test_mswin_event('mouse', args)
845
846 " Triple Click
847 let args.button = button
848 call test_mswin_event('mouse', args)
849 let args.multiclick = 1
850 call test_mswin_event('mouse', args)
851 call test_mswin_event('mouse', args)
852 let args.button = 3
853 let args.multiclick = 0
854 call test_mswin_event('mouse', args)
855
856 " Shift click
857 let args = #{button: button, row: 3, col: 7, multiclick: 0, modifiers: 4}
858 call test_mswin_event('mouse', args)
859 let args.button = 3
860 call test_mswin_event('mouse', args)
861
862 " Alt click
863 let args.button = button
864 let args.modifiers = 8
865 call test_mswin_event('mouse', args)
866 let args.button = 3
867 call test_mswin_event('mouse', args)
868
869 " Ctrl click
870 let args.button = button
871 let args.modifiers = 16
872 call test_mswin_event('mouse', args)
873 let args.button = 3
874 call test_mswin_event('mouse', args)
875
876 call feedkeys("\<Esc>", 'Lx!')
877 endfor
878
879 if has('gui_running')
880 call assert_equal(['LeftMouse', 'LeftRelease', 'LeftMouse',
881 \ '2-LeftMouse', 'LeftMouse', '2-LeftMouse', '3-LeftMouse',
882 \ 'S-LeftMouse', 'A-LeftMouse', 'C-LeftMouse', 'MiddleMouse',
883 \ 'MiddleRelease', 'MiddleMouse', '2-MiddleMouse', 'MiddleMouse',
884 \ '2-MiddleMouse', '3-MiddleMouse', 'S-MiddleMouse', 'A-MiddleMouse',
885 \ 'C-MiddleMouse', 'RightMouse', 'RightRelease', 'RightMouse',
886 \ '2-RightMouse', 'RightMouse', '2-RightMouse', '3-RightMouse',
887 \ 'S-RightMouse', 'A-RightMouse', 'C-RightMouse'],
888 \ g:events)
889 else
890 call assert_equal(['MiddleRelease', 'LeftMouse', '2-LeftMouse',
891 \ '3-LeftMouse', 'S-LeftMouse', 'MiddleMouse', '2-MiddleMouse',
892 \ '3-MiddleMouse', 'MiddleMouse', 'S-MiddleMouse', 'RightMouse',
893 \ '2-RightMouse', '3-RightMouse'],
894 \ g:events)
895 endif
896
897 for e in mouseEventCodes
898 exe 'nunmap ' .. e
899 endfor
900
901 bw!
902 call test_override('no_query_mouse', 0)
903 set mousemodel&
904endfunc
905
906
907" Test MS-Windows test_mswin_event error handling
908func Test_mswin_event_error_handling()
909
910 let args = #{button: 0xfff, row: 2, col: 4, move: 0, multiclick: 0, modifiers: 0}
911 if !has('gui_running')
912 call assert_fails("call test_mswin_event('mouse', args)",'E475:')
913 endif
914 let args = #{button: 0, row: 2, col: 4, move: 0, multiclick: 0, modifiers: 0}
915 call assert_fails("call test_mswin_event('a1b2c3', args)", 'E475:')
916 call assert_fails("call test_mswin_event(test_null_string(), {})", 'E475:')
917
918 call assert_fails("call test_mswin_event([], args)", 'E1174:')
919 call assert_fails("call test_mswin_event('abc', [])", 'E1206:')
920
921 call assert_false(test_mswin_event('mouse', test_null_dict()))
922 let args = #{row: 2, col: 4, multiclick: 0, modifiers: 0}
923 call assert_false(test_mswin_event('mouse', args))
924 let args = #{button: 0, col: 4, multiclick: 0, modifiers: 0}
925 call assert_false(test_mswin_event('mouse', args))
926 let args = #{button: 0, row: 2, multiclick: 0, modifiers: 0}
927 call assert_false(test_mswin_event('mouse', args))
928 let args = #{button: 0, row: 2, col: 4, modifiers: 0}
929 call assert_false(test_mswin_event('mouse', args))
930 let args = #{button: 0, row: 2, col: 4, multiclick: 0}
931 call assert_false(test_mswin_event('mouse', args))
932
933 call assert_false(test_mswin_event('key', test_null_dict()))
934 call assert_fails("call test_mswin_event('key', [])", 'E1206:')
935 call assert_fails("call test_mswin_event('key', {'event': 'keydown', 'keycode': 0x0})", 'E1291:')
936 call assert_fails("call test_mswin_event('key', {'event': 'keydown', 'keycode': [15]})", 'E745:')
937 call assert_fails("call test_mswin_event('key', {'event': 'keys', 'keycode': 0x41})", 'E475:')
938 call assert_fails("call test_mswin_event('key', {'keycode': 0x41})", 'E417:')
939 call assert_fails("call test_mswin_event('key', {'event': 'keydown'})", 'E1291:')
940
941 call assert_fails("sandbox call test_mswin_event('key', {'event': 'keydown', 'keycode': 61 })", 'E48:')
942
Christopher Plewrightc8b20492023-01-04 18:06:00 +0000943 " flush out anything in the typeahead buffer
Christopher Plewright20b795e2022-12-20 20:01:58 +0000944 while getchar(0)
945 endwhile
946endfunc
947
948
949" vim: shiftwidth=2 sts=2 expandtab