Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert System.Windows.Forms.Shortcut into KeyData / KeyCode

Is there an easy way to get the corresponding keydata (keycode combination) for some value in that enum?

I cannot find one, and creating a switch statement for all those is a bit overkill...

The integer values of the enum elements are not keycodes, but some 'unknown' big numbers, so simply casting to int won't work.

like image 761
Marino Šimić Avatar asked Oct 22 '25 03:10

Marino Šimić


2 Answers

System.Windows.Forms.Shortcut and System.Windows.Forms.Keys can be cast directly (their integer values match).

Keys keys = (Keys) Shortcut.CtrlL;
like image 117
Mike Fuchs Avatar answered Oct 24 '25 04:10

Mike Fuchs


The lower 4 bytes are the key and the upper 4 bytes are a mask for Shift, Ctrl and Alt-Key, So you can get the KeyCode with something like this:

Shortcut shortcut = Shortcut.ShiftDel;
Debug.Print((((int)shortcut) & 0xFFFF).ToString());

Will output 46 which is the code for del key.

like image 34
Fischermaen Avatar answered Oct 24 '25 03:10

Fischermaen