Hi list.

I wrote a patch to add {dict} argument to getcharmod().
`getcharmod(1)` returns Dictionary.

It is a hassle to see the modifier keys pressed
because Vimscript does not have bitwise AND operator.
If getcharmod() had the feature, it is no more necessary for yak shaving
like this:
https://github.com/tyru/stickykey.vim/blob/aabe981322e7be283b3fc005070e1f99f449558f/autoload/stickykey.vim#L87-L126

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff -r 9abd62fd9e3a runtime/doc/eval.txt
--- a/runtime/doc/eval.txt	Wed Nov 30 17:20:23 2011 +0100
+++ b/runtime/doc/eval.txt	Thu Dec 01 22:26:49 2011 +0900
@@ -1773,7 +1773,7 @@
 				List	lines {lnum} to {end} of buffer {expr}
 getbufvar( {expr}, {varname})	any	variable {varname} in buffer {expr}
 getchar( [expr])		Number	get one character from the user
-getcharmod( )			Number	modifiers for the last typed character
+getcharmod( [{dict}])			Number	modifiers for the last typed character
 getcmdline()			String	return the current command-line
 getcmdpos()			Number	return cursor position in command-line
 getcmdtype()			String	return the current command-line type
@@ -3182,7 +3182,7 @@
 			:  endwhile
 			:endfunction
 
-getcharmod()						*getcharmod()*
+getcharmod([{dict}])						*getcharmod()*
 		The result is a Number which is the state of the modifiers for
 		the last obtained character with getchar() or in another way.
 		These values are added together:
@@ -3197,6 +3197,17 @@
 		character itself are obtained.	Thus Shift-a results in "A"
 		without a modifier.
 
+		When {dict} is there and it is non-zero return a dictionary
+		containing all the information of the mapping with the
+		following items:
+		  "shift"			1 if shift-key pressed, else 0.
+		  "ctrl"			1 if ctrl-key pressed, else 0.
+		  "alt"				1 if alt-key pressed, else 0.
+		  "mousedouble"		1 if mouse clicked twice, else 0.
+		  "mousetriple"		1 if mouse clicked thrice, else 0.
+		  "mousequad"		1 if mouse clicked quater, else 0.
+		  "command"			1 if command-key pressed, else 0.
+
 getcmdline()						*getcmdline()*
 		Return the current command-line.  Only works when the command
 		line is being edited, thus requires use of |c_CTRL-\_e| or
diff -r 9abd62fd9e3a src/eval.c
--- a/src/eval.c	Wed Nov 30 17:20:23 2011 +0100
+++ b/src/eval.c	Thu Dec 01 22:26:49 2011 +0900
@@ -7802,7 +7802,7 @@
     {"getbufline",	2, 3, f_getbufline},
     {"getbufvar",	2, 2, f_getbufvar},
     {"getchar",		0, 1, f_getchar},
-    {"getcharmod",	0, 0, f_getcharmod},
+    {"getcharmod",	0, 1, f_getcharmod},
     {"getcmdline",	0, 0, f_getcmdline},
     {"getcmdpos",	0, 0, f_getcmdpos},
     {"getcmdtype",	0, 0, f_getcmdtype},
@@ -11063,10 +11063,35 @@
  */
     static void
 f_getcharmod(argvars, rettv)
-    typval_T	*argvars UNUSED;
-    typval_T	*rettv;
-{
-    rettv->vval.v_number = mod_mask;
+    typval_T	*argvars;
+    typval_T	*rettv;
+{
+    int dict = FALSE;
+    if (argvars[0].v_type == VAR_NUMBER)
+    {
+	int error = FALSE;
+	dict = get_tv_number_chk(&argvars[0], &error);
+	if (error)
+	    return;
+    }
+    if (dict)
+    {
+	dict_T *dict;
+	if (rettv_dict_alloc(rettv) == FAIL)
+	    return;
+	dict = rettv->vval.v_dict;
+	dict_add_nr_str(dict, "shift", mod_mask & 2, NULL);
+	dict_add_nr_str(dict, "ctrl", mod_mask & 4, NULL);
+	dict_add_nr_str(dict, "alt", mod_mask & 8, NULL);
+	dict_add_nr_str(dict, "mousedouble", mod_mask & 16, NULL);
+	dict_add_nr_str(dict, "mousetriple", mod_mask & 32, NULL);
+	dict_add_nr_str(dict, "mousequad", mod_mask & 64, NULL);
+	dict_add_nr_str(dict, "command", mod_mask & 128, NULL);
+    }
+    else
+    {
+	rettv->vval.v_number = mod_mask;
+    }
 }
 
 /*

Raspunde prin e-mail lui