storing Keys::*** in array

Hi There,

I am creating a c++ .net program which needs to check which button on the keyboard has been pressed. My ideal way to do this is to use an array to store the Keys::__ values so that I can check each through a loop.

I think my problem is that I do not know the data type to create the array with.

My code at the moment is something like:
1
2
3
4
5
6
7
8
9
10
 array<char>^ buttonMap = gcnew array<char>(Keys);
 buttonMap[0] = Keys::Q;
 buttonMap[1] = Keys::W;
 // [tab]QWERTYUIOP[]\	/
 if (e->KeyCode == buttonMap[0]) {    // this is how I would like to access the value, although it will eventually be done in a loop
	 codeBox->Text = codeBox->Text+"ln(";
 }
 if (e->KeyCode == Keys::W) {    // How it currently works, but this will not enable me to use a loop to run through all characters.
		 codeBox->Text = codeBox->Text+"log(";
 }


Any help would be greatly appreciated!

Cheers,
Elliott
closed account (DSLq5Di1)
http://msdn.microsoft.com/en-us/library/system.enum.getvalues.aspx
Cheers, that looks like it is exactly what I am after! Thanks!
Ok, I've looked into this a bit further and this would not quite work as I need to map the enum values to specific positions in the array. I have modified my code to the following, but this does not seem to work.

1
2
3
4
5
6
	array<Enum^>^ buttonMap = gcnew array<Enum^>(255);
	buttonMap[0] = Keys::Q;
	if (e->KeyCode == buttonMap[0])
	{
		//
	}
closed account (DSLq5Di1)
Ooh.. I didn't think you intended to create your own array of Keys.

1
2
3
4
5
6
7
8
9
10
11
12
array<Keys::typeid^>^ buttonMap = gcnew array<Keys::typeid^>(255);
buttonMap[0] = Keys::Q;
buttonMap[1] = Keys::W;
...

for each (Keys::typeid^ key in buttonMap)
{
    if (e->KeyCode == key)
    {
        ...
    }
}

I'm not certain if this is correct as I don't use C++/CLI, but hopefully that works or may guide you in the right direction. ^^
ah, I tried that, I get the following error (among others):
1>c:\...\Form1.h(111): error C2059: syntax error : '>'

relating to the array<Keys::typeid^>^... line

I am quite unfamilar with the whole enum thing and slowly starting to get a bit of understanding!
closed account (DSLq5Di1)
I created a managed project to play around with, and it seems you don't even need that typeid fluff:-

array<Keys>^ buttonMap = gcnew array<Keys>(255);
haha! You're a legend! It works perfectly! hmm, you have no idea how many different combinations and permutations I tried - as always it looks exceedingly easy and simple when figured out!
Topic archived. No new replies allowed.