Marino Šimić
Marino Šimić

Reputation: 7342

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.

Upvotes: 4

Views: 988

Answers (2)

Mike Fuchs
Mike Fuchs

Reputation: 12319

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

Keys keys = (Keys) Shortcut.CtrlL;

Upvotes: 3

Fischermaen
Fischermaen

Reputation: 12468

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.

Upvotes: 1

Related Questions