This seems like something that should be easy, but I am having a tough time figuring out what needs to happen here.
In the "KeyDown" eventhandler, if the "e.KeyValue" is a number, I want to treat it as a number and store it as an int. So, if I hit "8" on the number pad, I don't want "Numpad8" I want the int value 8 that I can add or subtract or whatever.
So, how do I convert from the KeyValue to an int?
The KeyValue represents the character code for the key that was pressed. In order to obtain its numerical valaue you should find the character for the key that was pressed, then parse it from a character to an integer.
Something like Convert.ToInt32(e.KeyCode.ToString())
Depending on how many keys you are keeping track of, the simplest method would be for you to create a select case (or switch statement in C# I guess?) that would check the value of your keydown and depending upon that value assign a value to an integer that is appropriate.
Something like this should work well: (Edited)
If you want NUMERIC values, you'll have to create a
switch(e.KeyCode)
statement and evaluate the key and create your own int. There's no simple way to turn aKeys
into a numeric value that represents the number on the key. The closest you could get might be the ASCII equivalent, which would still need to be translated.Could you just listen for the
KeyPress
event instead? It will give the character that was actually pressed.This function will do what you want:
Call it like so: