GetAsyncKeyState() on MSDN
However, if you wanted to check for an ALT+something keypress in a console, try this:
Code:
#include <windows.h>
#include <iostream>
bool ALT(char key)
{
HANDLE hInConsole = GetStdHandle(STD_INPUT_HANDLE);
INPUT_RECORD Event, SecondEvent;
DWORD NumberOfEvents, EventsRead, EventCounter, NumberOfSecondEvents, SecondEventsRead;
GetNumberOfConsoleInputEvents(hInConsole, &NumberOfEvents);
if (NumberOfEvents == 0)
return false;
for (EventCounter = 0; EventCounter < NumberOfEvents; EventCounter++)
{
PeekConsoleInput(hInConsole, &Event, 1, &EventsRead);
if (Event.EventType == KEY_EVENT)
{
ReadConsoleInput(hInConsole, &Event, 1, &EventsRead);
if (Event.Event.KeyEvent.wVirtualKeyCode == VK_MENU)
while (Event.Event.KeyEvent.bKeyDown)
{
FlushConsoleInputBuffer(hInConsole);
GetNumberOfConsoleInputEvents(hInConsole, &NumberOfSecondEvents);
PeekConsoleInput(hInConsole, &SecondEvent, 1, &SecondEventsRead);
if (SecondEvent.EventType == KEY_EVENT && SecondEvent.Event.KeyEvent.bKeyDown)
if (SecondEvent.Event.KeyEvent.uChar.AsciiChar == key)
return true;
}
}
else
ReadConsoleInput(hInConsole, &Event, 1, &EventsRead);
}
return false;
}
int main()
{
std::cout << "Press ALT+F to quit\n";
while(!ALT('f')) {}
std::cout << "Wait! Now press ALT+Q!\n";
while(!ALT('q')) {}
std::cout << "Hehehe, now press ALT+X and you may go. . .\n";
while(!ALT('x')) {}
return 0;
}
Works for me