geting input from specific keys

closed account (N8MNAqkS)
I pulled this code off an older thread while I was learning how to get input from specific keys on the keyboard, rather then using std::cin as a way to simulate buttons.

this is going to be very useful to me, but I dont want to use it if I dont completely understand it.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
	DWORD NumInputs = 0;
	DWORD InputsRead = 0;
	bool running = true;

	INPUT_RECORD irInput;

	GetNumberOfConsoleInputEvents(hInput, &NumInputs);

	while (running)
	{
		ReadConsoleInput(hInput, &irInput, 1, &InputsRead);
		//std::cout << irInput.Event.KeyEvent.wVirtualKeyCode << std::endl;

		switch (irInput.Event.KeyEvent.wVirtualKeyCode)
		{
		case VK_ESCAPE:
			running = false;
			//Quit The Running Loop
			break;
		case VK_LEFT: std::cout << "left";
		case VK_NUMPAD4:std::cout << "dont do that";
			// move it left
			break;
		case VK_UP:std::cout << "up";
		case VK_NUMPAD8:std::cout << "dont do that";
			// move it up
			break;
		case VK_RIGHT:std::cout << "right";
		case VK_NUMPAD6:std::cout << "dont do that";
			// move it right
			break;
		case VK_DOWN:std::cout << "down";
		case VK_NUMPAD2:std::cout << "dont do that";
			// move it down
			break;
		}


so here is what I do know. I know how switch and case works, I know what the VK_LEFT does, its a keyword associated with the left arrow key.

what I dont understand is pretty much anything above the switch function:



HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
DWORD NumInputs = 0;
DWORD InputsRead = 0;
bool running = true;

INPUT_RECORD irInput;

GetNumberOfConsoleInputEvents(hInput, &NumInputs);

while (running)
{
ReadConsoleInput(hInput, &irInput, 1, &InputsRead);
//std::cout << irInput.Event.KeyEvent.wVirtualKeyCode << std::endl;

so from what I understand:

DWORD is like a data type, one that only holds up to a curtain amount of bits(I believe this one holds 32 but I am not sure) WORD and QWORD do a similar thing.


HANDLE from what I can gather is apart of the WinAPI and works kind of like a pointer? but I am not sure what it is doing here.


i dont understand anything else
Topic archived. No new replies allowed.