views:

297

answers:

2
+1  Q: 

Register Hotkey

I have this function: RegisterGlobalHotKey(Keys.F6, MOD_SHIFT | MOD_CONTROL); which call an API to register a global shortcut key in the system. void RegisterGlobalHotKey(Keys hotkey, int modifiers)

I created a small options form to set this keys to be variables not fixed values like this: RegisterGlobalHotKey(VARIABLE1, VARIABLE2 | VARIABLE3);

See the attached option form to understand more

The main problem is how to convert the combobox string values to Keys enum value

+1  A: 

Assuming that you can require users to type in the name of the Enum values exactly, you can pass the text to Enum.Parse and that will return the enum value with the specified name.

Andy
A: 

How about a map of your strings to Keys, and your other strings to modifiers?

Map Map

That would avoid a bunch of if-else string comparisons in your code.

EDIT: Actually, I think I've also used Andy's suggestion in the past as well.

JMD