I want to create an accelerator for CTRL+A. I noticed that it doesn't work when you leave out FVIRTKEY, i.e. the following code snippet doesn't work:
a.fVirt = FCONTROL;
a.key = 'A';
a.cmd = IDM_ADD;
(just for completeness' sake: using 'a' instead of 'A' doesn't work either)
This, however, works fine:
a.fVirt = FCONTROL|FVIRTKEY;
a.key = 'A';
a.cmd = IDM_ADD;
Can somebody explain this behaviour? MSDN says that if FVIRTKEY isn't set, "key" is interpreted as a character code which I presume to be ASCII. But it doesn't work which leaves me somewhat puzzled.
Thanks!
The system translates certain Ctrl key combinations into ASCII control codes. The combination Ctrl+A is translated to the ASCII ctrl-A (SOH) character (ASCII value 0x01). This is the reason why your first snippet does not expose the desired behavior: It requires input that is impossible to enter. This is documented under Keyboard Input in the MSDN.
Also note that not providing the FVIRTKEY flag makes the specified key case-sensitive, i.e. 'a' and 'A' map to different input. It is usually desirable to use virtual key codes, to provide a consistent keyboard UI. The implications are explained under About Keyboard Accelerators - Accelerator Keystroke Assignments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With