To: vim_dev@googlegroups.com Subject: Patch 9.0.0058 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0058 Problem: Win32: cannot test low level events. Solution: Add "sendevent" to test_gui_event(). (Yegappan Lakshmanan, closes #10679) Files: runtime/doc/testing.txt, src/errors.h, src/gui_w32.c, src/proto/gui_w32.pro, src/testing.c, src/testdir/test_gui.vim *** ../vim-9.0.0057/runtime/doc/testing.txt 2022-06-30 22:13:56.200846349 +0100 --- runtime/doc/testing.txt 2022-07-23 04:53:50.664660917 +0100 *************** *** 94,99 **** --- 94,100 ---- "findrepl" search and replace text. "mouse" mouse button click event. "scrollbar" move or drag the scrollbar. + "sendevent" send a low-level GUI event. "tabline" select a tab page by mouse click. "tabmenu" select a tabline menu entry. *************** *** 177,182 **** --- 178,192 ---- dragging: 1 to drag the scrollbar and 0 to click in the scrollbar. + "sendevent": + Send a low-level GUI event (e.g. key-up or down). + Currently only supported on MS-Windows. + The supported items in {args} are: + event: The supported string values are: + keyup generate a keyup event + keydown generate a keydown event + keycode: Keycode to use for a keyup or a keydown event. + "tabline": Inject a mouse click event on the tabline to select a tabpage. The supported items in {args} are: *** ../vim-9.0.0057/src/errors.h 2022-06-21 21:15:26.000000000 +0100 --- src/errors.h 2022-07-23 04:58:56.944749759 +0100 *************** *** 3303,3306 **** --- 3303,3308 ---- #ifdef FEAT_EVAL EXTERN char e_substitute_nesting_too_deep[] INIT(= N_("E1290: substitute nesting too deep")); + EXTERN char e_invalid_argument_nr[] + INIT(= N_("E1291: Invalid argument: %ld")); #endif *** ../vim-9.0.0057/src/gui_w32.c 2022-06-27 22:29:57.000000000 +0100 --- src/gui_w32.c 2022-07-23 04:59:51.140764849 +0100 *************** *** 8541,8543 **** --- 8541,8582 ---- SetPixel(s_hdc, x+2, y, gui.currFgColor); } #endif + + #if defined(FEAT_EVAL) || defined(PROTO) + int + test_gui_w32_sendevent(dict_T *args) + { + char_u *event; + INPUT inputs[1]; + + event = dict_get_string(args, "event", TRUE); + if (event == NULL) + return FALSE; + + ZeroMemory(inputs, sizeof(inputs)); + + if (STRICMP(event, "keydown") == 0 || STRICMP(event, "keyup") == 0) + { + WORD vkCode; + + vkCode = dict_get_number_def(args, "keycode", 0); + if (vkCode <= 0 || vkCode >= 0xFF) + { + semsg(_(e_invalid_argument_nr), (long)vkCode); + return FALSE; + } + + inputs[0].type = INPUT_KEYBOARD; + inputs[0].ki.wVk = vkCode; + if (STRICMP(event, "keyup") == 0) + inputs[0].ki.dwFlags = KEYEVENTF_KEYUP; + SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT)); + } + else + semsg(_(e_invalid_argument_str), event); + + vim_free(event); + + return TRUE; + } + #endif *** ../vim-9.0.0057/src/proto/gui_w32.pro 2022-06-27 23:15:33.000000000 +0100 --- src/proto/gui_w32.pro 2022-07-23 04:50:06.952580864 +0100 *************** *** 96,99 **** --- 96,100 ---- BalloonEval *gui_mch_create_beval_area(void *target, char_u *mesg, void (*mesgCB)(BalloonEval *, int), void *clientData); void gui_mch_destroy_beval_area(BalloonEval *beval); void netbeans_draw_multisign_indicator(int row); + int test_gui_w32_sendevent(dict_T *args); /* vim: set ft=c : */ *** ../vim-9.0.0057/src/testing.c 2022-06-30 22:28:04.069963729 +0100 --- src/testing.c 2022-07-23 04:50:06.952580864 +0100 *************** *** 1500,1505 **** --- 1500,1511 ---- rettv->v_type = VAR_BOOL; rettv->vval.v_number = FALSE; + if (sandbox != 0) + { + emsg(_(e_not_allowed_in_sandbox)); + return; + } + if (check_for_string_arg(argvars, 0) == FAIL || check_for_dict_arg(argvars, 1) == FAIL || argvars[1].vval.v_dict == NULL) *************** *** 1520,1525 **** --- 1526,1535 ---- rettv->vval.v_number = test_gui_tabline_event(argvars[1].vval.v_dict); else if (STRCMP(event, "tabmenu") == 0) rettv->vval.v_number = test_gui_tabmenu_event(argvars[1].vval.v_dict); + # ifdef FEAT_GUI_MSWIN + else if (STRCMP(event, "sendevent") == 0) + rettv->vval.v_number = test_gui_w32_sendevent(argvars[1].vval.v_dict); + # endif else { semsg(_(e_invalid_argument_str), event); *** ../vim-9.0.0057/src/testdir/test_gui.vim 2022-06-26 22:55:35.000000000 +0100 --- src/testdir/test_gui.vim 2022-07-23 04:50:06.952580864 +0100 *************** *** 1606,1609 **** --- 1606,1693 ---- call delete('Xlines') endfunc + " Test for sending low level key presses + func SendKeys(keylist) + for k in a:keylist + call test_gui_event("sendevent", #{event: "keydown", keycode: k}) + endfor + for k in reverse(a:keylist) + call test_gui_event("sendevent", #{event: "keyup", keycode: k}) + endfor + endfunc + + func Test_gui_lowlevel_keyevent() + CheckMSWindows + new + + " Test for to keys + for kc in range(65, 90) + call SendKeys([0x11, kc]) + let ch = getcharstr() + call assert_equal(nr2char(kc - 64), ch) + endfor + + " Test for the various Ctrl and Shift key combinations. + let keytests = [ + \ [[0x10, 0x21], "\", 2], + \ [[0x11, 0x21], "\", 4], + \ [[0x10, 0x22], "\", 2], + \ [[0x11, 0x22], "\", 4], + \ [[0x10, 0x23], "\", 0], + \ [[0x11, 0x23], "\", 0], + \ [[0x10, 0x24], "\", 0], + \ [[0x11, 0x24], "\", 0], + \ [[0x10, 0x25], "\", 0], + \ [[0x11, 0x25], "\", 0], + \ [[0x10, 0x26], "\", 0], + \ [[0x11, 0x26], "\", 4], + \ [[0x10, 0x27], "\", 0], + \ [[0x11, 0x27], "\", 0], + \ [[0x10, 0x28], "\", 0], + \ [[0x11, 0x28], "\", 4], + \ [[0x11, 0x30], "\", 4], + \ [[0x11, 0x31], "\", 4], + \ [[0x11, 0x32], "\", 4], + \ [[0x11, 0x33], "\", 4], + \ [[0x11, 0x34], "\", 4], + \ [[0x11, 0x35], "\", 4], + \ [[0x11, 0x36], "\", 0], + \ [[0x11, 0x37], "\", 4], + \ [[0x11, 0x38], "\", 4], + \ [[0x11, 0x39], "\", 4], + \ [[0x11, 0x60], "\", 4], + \ [[0x11, 0x61], "\", 4], + \ [[0x11, 0x62], "\", 4], + \ [[0x11, 0x63], "\", 4], + \ [[0x11, 0x64], "\", 4], + \ [[0x11, 0x65], "\", 4], + \ [[0x11, 0x66], "\", 4], + \ [[0x11, 0x67], "\", 4], + \ [[0x11, 0x68], "\", 4], + \ [[0x11, 0x69], "\", 4], + \ [[0x11, 0x6A], "\", 4], + \ [[0x11, 0x6B], "\", 4], + \ [[0x11, 0x6D], "\", 4], + \ [[0x11, 0x70], "\", 4], + \ [[0x11, 0x71], "\", 4], + \ [[0x11, 0x72], "\", 4], + \ [[0x11, 0x73], "\", 4], + \ [[0x11, 0x74], "\", 4], + \ [[0x11, 0x75], "\", 4], + \ [[0x11, 0x76], "\", 4], + \ [[0x11, 0x77], "\", 4], + \ [[0x11, 0x78], "\", 4], + \ ] + + for [kcodes, kstr, kmod] in keytests + call SendKeys(kcodes) + let ch = getcharstr() + let mod = getcharmod() + call assert_equal(kstr, ch, $"key = {kstr}") + call assert_equal(kmod, mod) + endfor + + bw! + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-9.0.0057/src/version.c 2022-07-18 20:48:43.428351586 +0100 --- src/version.c 2022-07-23 05:00:54.188782743 +0100 *************** *** 737,738 **** --- 737,740 ---- { /* Add new patch number below this line */ + /**/ + 58, /**/ -- hundred-and-one symptoms of being an internet addict: 97. Your mother tells you to remember something, and you look for a File/Save command. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///