I'm trying to make a switch statement that will handle hotkeys assigned to different functions in my application. The hotkeys will be user-changable, so I've got them saved as application settings. I have a class that allows the program to hook the keyboard and accept the hotkeys even if the program doesn't have focus. In the event handler for that hook I'm trying to create a switch statement that looks like this:
But I'm getting an error:
"A constant value is expected"
I don't know what that means though. All I want is for the first case to fire if e.KeyCode equals the one I have saved for hotkey1, and the same for if e.KeyCode is hotkey2. How can I make it let me do that? I don't want to have a bunch of if statements, that would defeat the purpose of a switch statement existing.
Any ideas?
Code:
switch (e.KeyCode) { case settings.hotkey1: MessageBox.Show("Hot Key 1"); break; case settings.hotkey2: MessageBox.Show("Hot Key 2"); break; }
"A constant value is expected"
I don't know what that means though. All I want is for the first case to fire if e.KeyCode equals the one I have saved for hotkey1, and the same for if e.KeyCode is hotkey2. How can I make it let me do that? I don't want to have a bunch of if statements, that would defeat the purpose of a switch statement existing.
Any ideas?
Comment