" Test MS-Windows input event handling.
" Most of this works the same in Windows GUI as well as Windows console.
source check.vim
CheckMSWindows
source mouse.vim
" Helper function for sending a grouped sequence of low level key presses
" The modifer key(s) can be included as VK Key Codes in the sequence
" Keydown events will be sent, to to the end of the group, then keyup events
" will be sent in reverse order to release the keys.
func SendKeyGroup(keygroup)
for k in a:keygroup
call test_mswin_event("key", {'event': "keydown", 'keycode': k})
endfor
for k in reverse(copy(a:keygroup))
call test_mswin_event("key", {'event': "keyup", 'keycode': k})
endfor
endfunc
" Send individual key press and release events.
" the modifers for the key press can be specified in the modifiers arg.
func SendKeyWithModifiers(key, modifiers)
let args = { }
let args.keycode = a:key
let args.modifiers = a:modifiers
let args.event = "keydown"
call test_mswin_event("key", args)
let args.event = "keyup"
call test_mswin_event("key", args)
unlet args
endfunc
" Send an individual key press, without modifiers.
func SendKey(key)
call SendKeyWithModifiers(a:key, 0)
endfunc
" Send a string of individual key-press events, without modifiers.
func SendKeyStr(keystring)
for k in a:keystring
call SendKey(k)
endfor
endfunc
" This tells Vim to execute the buffered keys as user commands,
" ie. same as feekdeys with mode X would do.
func ExecuteBufferedKeys()
if has('gui_running')
call feedkeys("\<Esc>", 'Lx!')
else
call test_mswin_event("key", {'execute': v:true})
endif
endfunc
" Refer to the following page for the virtual key codes:
" https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
let s:VK = {
\ 'ENTER' : 0x0D,
\ 'SPACE' : 0x20,
\ 'SHIFT' : 0x10,
\ 'LSHIFT' : 0xA0,
\ 'RSHIFT' : 0xA1,
\ 'CONTROL' : 0x11,
\ 'LCONTROL' : 0xA2,
\ 'RCONTROL' : 0xA3,
\ 'MENU' : 0x12,
\ 'ALT' : 0x12,
\ 'LMENU' : 0xA4,
\ 'LALT' : 0xA4,
\ 'RMENU' : 0xA5,
\ 'RALT' : 0xA5,
\ 'OEM_1' : 0xBA,
\ 'OEM_2' : 0xBF,
\ 'OEM_3' : 0xC0,
\ 'OEM_4' : 0xDB,
\ 'O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' : 0x67,
\ 'NUMPAD8' : 0x68,
\ 'NUMPAD9' : 0x69,
\ 'MULTIPLY' : 0x6A,
\ 'ADD' : 0x6B,
\ 'SUBTRACT' : 0x6D,
\ 'F1' : 0x70,
\ 'F2' : 0x71,
\ 'F3' : 0x72,
\ 'F4' : 0x73,
\ 'F5' : 0x74,
\ 'F6' : 0x75,
\ 'F7' : 0x76,
\ 'F8' : 0x77,
\ 'F9' : 0x78,
\ 'F10' : 0x79,
\ 'F11' : 0x7A,
\ 'F12' : 0x7B,
\ 'DELETE' : 0x2E,
\ 'BACK' : 0x08,
\ 'ESCAPE' : 0x1B
\ }
let s:MOD_MASK_SHIFT = 0x02
let s:MOD_MASK_CTRL = 0x04
let s:MOD_MASK_ALT = 0x08
let s:vim_key_modifiers = [
\ ["", 0, []],
\ ["S-", 2, [s:VK.LSHIFT]],
\ ["C-", 4, [s:VK.LCONTROL]],
\ ["C-S-", 6, [s:VK.LCONTROL, s:VK.LSHIFT]],
\ ["A-", 8, [s:VK.LMENU]],
\ ["A-S-", 10, [s:VK.LMENU, s:VK.LSHIFT]],
\ ["A-C-", 12, [s:VK.LMENU, s:VK.LCONTROL]],
\ ["A-C-S-", 14, [s:VK.LMENU, s:VK.LCONTROL, s:VK.LSHIFT]],
\]
" Assuming Standard US PC Keyboard layout
let s:test_ascii_key_chars = [
\ [[s:VK.SPACE], ' '],
\ [[s:VK.OEM_1], ';'],
\ [[s:VK.OEM_2], '/'],
\ [[s:VK.OEM_3], '`'],
\ [[s:VK.OEM_4], '['],
\ [[s:VK.OEM_5], '\'],
\ [[s:VK.OEM_6], ']'],
\ [[s:VK.OEM_7], ''''],
\ [[s:VK.OEM_PLUS], '='],
\ [[s:VK.OEM_COMMA], ','],
\ [[s:VK.OEM_MINUS], '-'],
\ [[s:VK.OEM_PERIOD], '.'],
\ [[s:VK.SHIFT, s:VK.OEM_1], ':'],
\ [[s:VK.SHIFT, s:VK.OEM_2], '?'],
\ [[s:VK.SHIFT, s:VK.OEM_3], '~'],
\ [[s:VK.SHIFT, s:VK.OEM_4], '{'],
\ [[s:VK.SHIFT, s:VK.OEM_5], '|'],
\ [[s:VK.SHIFT, s:VK.OEM_6], '}'],
\ [[s:VK.SHIFT, s:VK.OEM_7], '"'],
\ [[s:VK.SHIFT, s:VK.OEM_PLUS], '+'],
\ [[s:VK.SHIFT, s:VK.OEM_COMMA], '<'],
\ [[s:VK.SHIFT, s:VK.OEM_MINUS], '_'],
\ [[s:VK.SHIFT, s:VK.OEM_PERIOD], '>'],
\ [[s:VK.KEY_1], '1'],
\ [[s:VK.KEY_2], '2'],
\ [[s:VK.KEY_3], '3'],
\ [[s:VK.KEY_4], '4'],
\ [[s:VK.KEY_5], '5'],
\ [[s:VK.KEY_