Windows keyboard input
Hi. I''m trying to get some extra credit for my physics class by making a 3D graph in openGL. I want to have limited camera control to move around the graph, but my computer says otherwise. I''m trying doing input like this:
At the top of my program, I have a global variable:
bool keysDown[256]
In my WinProcedure function, I have the message switch looking for WM_KEYDOWN and WM_KEYUP:
...
case WM_KEYDOWN:
keysDown[lparam] = true;
break;
case WM_KEYUP:
keysDown[lparam] = false;
break;
....
It compiles all fine but when I run it, it crashes whenever I hit a key, giving me one of those illegal operation err deelies. Here''s what it says:
GRAPHTEST caused an invalid page fault in
module GRAPHTEST.EXE at 0177:004012c1.
Registers:
EAX=011c0001 CS=0177 EIP=004012c1 EFLGS=00010246
EBX=0065fc14 SS=017f ESP=0065fb38 EBP=0065fb94
ECX=00000000 DS=017f ESI=0053075c FS=36ff
EDX=00008c54 ES=017f EDI=0065fb94 GS=2a9f
Bytes at CS:EIP:
c6 80 60 9c 42 00 01 eb 0a 8b 4d 14 c6 81 60 9c
Stack dump:
00000000 0053075c 0065fc14 cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc cccccccc
Pressing DEBUG, I get a message saying:
Unhandled exception in graphtest.exe: 0xC0000005: Access Violation
And finally I get a little arrow pointing to the line:
case WM_KEYDOWN:
g_keys[lparam] = true;
break;
Can anyone help me figure out what''s gone awry here? Thnx in advance.
October 03, 2002 10:47 PM
try wParam, not lParam.
(more info: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputmessages/wm_keydown.asp)
(more info: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputmessages/wm_keydown.asp)
October 04, 2002 08:17 AM
Your loc says IL... are you in college, and are you attending in IL?
instead of keeping track of 256 keys all at once, use GetAsyncKeyState(virtual_keycode) to check if certain keys are down or up. GetAsyncKeyState returns true if the key is down and false if the key is up. I forget what the values of the key codes are, but they are defined as constants in the windows header files, so you can look them up in your help files.
[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement