If you want to know the current state of the keys right now, you can use GetAsyncKeyState()
with an argument of VK_LSHIFT
or VK_RMENU
for left shift and right alt respectively. Make sure to test the most significant bit of the result, since the result contains more than one bit of information, e.g.
if(GetAsyncKeyState(VK_LSHIFT) & 0x8000)
; // left shift is currently down
If you instead want to be notified of keypresses instead of polling them asynchronously, you should listen for the WM_KEYDOWN
window notification. Put something like this in your window's message handler:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
...
case WM_KEYDOWN:
if(wparam == VK_LSHIFT)
; // left shift was pressed
// etc.
break;
}
}
You'll also have to handle the WM_KEYUP
message to know when keys are released.