Storing hexadecimal values without converting.

I need to store some hexadecimal values without converting them.
1
2
3
4
5
6
7
8
9
10
11
12
  vector <unsigned char> keyStates (0x1B, 0x49);
	system("PAUSE");
	for (int i = 0; i != keyStates.size(); i++)
	{
		cout << "Index: " << i << endl;
		cout << "keyState[i]" << keyStates[i] << endl;
      if (GetAsyncKeyState(keyStates[i]) & 0x8000)
      {
		  cout << "FOUND KEY!";
          return keyStates[i];
      }
	}

This converts the hexadecimal values to their corresponding character values. I need to store these as raw hex values.
Last edited on
Try to force integer promoition on values: std::cout << "keyState[i]" << +keyStates[i] << '\n';
Will try thanks
Did not work but thanks
Can you please be more specific. What did not work?
It still outputs as char? This is impossible unless your compiler is so substandard that it simpy shouldn't be used.
It outputs as a decimal number? You forgot to tell output stream to outpun numbers as hexadecimal by using std::hex
Well, the cout was just to see what is actually inside the vector, I want it to be converted to a hex value when it is used as a parameter for GetAsyncKeyState. If I use std::hex on cout it does work for printing, but the the char is still a char when passed on as a parameter. You see GetAsyncKeyState accepts a hex value.
You see GetAsyncKeyState accepts a hex value.
GetAsyncKeyState actually accepts a single int as a parameter which is in fact, a virtual key code.

See here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646293%28v=vs.85%29.aspx

and here: http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx

This line:
vector <unsigned char> keyStates (0x1B, 0x49);
creates a vector with 27 (0x1B) elements that all have the decimal value 73 (0x49). Because they are of the type unsigned char, they are treat as such when calling std::cout. Is this really what you wanted to do?
Last edited on
You see GetAsyncKeyState accepts a hex value.

There is no such thng as hexadecimal value. 20 apples, twenty apples and 0x14 apples is the same amount of apples. Integral values store such abstract numbers. GetAsyncKeyState takes int: an abstract number. It does not matter if you will pass 0x1B, 27 or constant VK_ESCAPE. It is the same thing.
the char is still a char when passed on as a parameter
How did you come to such conclusion? It will be promoted to int as per rules of conversions in C++.

EDIT: your vector might not contain values you expect. Right now it contains 27 (0x1B) copies of 0x49 value (I symbol code). It works fine to detect if I was pressed thought
Last edited on
I fixed my code, thanks for the help. The purpose of my program was to create "hotkeys" for programming in Unity because of the verbose language used.
Topic archived. No new replies allowed.