I am making a program and I want it to be able to read key presses. It does that just fine but I am running into some trouble when I am trying to get the name of the key that was pressed. The code just stops in the middle of the program and for what part is ran it does not give the expected output. Here is my code.
#include <iostream>
#include <Windows.h>
#pragma comment(lib, "User32.lib")
using std::cout;
using std::endl;
using std::wcout;
void test(short vk)
{
WCHAR key[16];
GetKeyNameTextW(MapVirtualKeyW(vk, MAPVK_VK_TO_CHAR), key, _countof(key));
wcout << "Key: " << key << endl;
}
int main()
{
cout << "Running...." << endl;
test(0x44); // Key: D
test(0x45); // Key: E
test(0x46); // Key: F
return 0;
}
The output this gives me is
Running....
Key:
and the output I am expecting is
Running....
Key: D
Key: E
Key: F
or at least something very close to that. It should display that those three hexadecimal numbers represent D, E, and F.
The test function is one I made to test turning the virtual key codes into the keys they represent but have so far been unsuccessful. Any help is appreciated!