您好我正在Windows7上用c ++创建一个游戏并遇到了一个奇怪的问题:
我使用GetKeyState来检索关键状态,到现在为止一直运行良好。
我已经映射了几个键:( INPUTKEY是整数)
const static INPUTKEY KEY_W = 87;
const static INPUTKEY KEY_S = 83;
const static INPUTKEY KEY_A = 65;
const static INPUTKEY KEY_D = 68;
const static INPUTKEY KEY_I = 73; // this one is not working
const static INPUTKEY KEY_V = 86;
我无法获得Key"我"工作它只是返回它没有被按下0X0000
这是我的获取功能:
inline static bool isKeyPressed(int keyCode){
return (GetKeyState(keyCode) & 0x8000);
}
有谁知道原因可能是什么。在我的窗口MESSAGES循环中,我与Key I没有任何关系......
这是窗口循环:
void Window::run() {
MSG msg;
displayState = 1;
while(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
LRESULT CALLBACK Window::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
Window* window = ((Window*) GetWindowLongPtr(hWnd, GWLP_USERDATA));
switch(message) {
case WM_PAINT:
DefWindowProc(hWnd, message, wParam, lParam);
break;
case WM_CLOSE:
window->isCloseRequestedBool = true;
break;
case WM_LBUTTONDOWN:
window->getMousePressState()->leftMouse = true;
DefWindowProc(hWnd, message, wParam, lParam);
break;
case WM_LBUTTONUP:
window->getMousePressState()->leftMouse = false;
DefWindowProc(hWnd, message, wParam, lParam);
break;
case WM_RBUTTONDOWN:
window->getMousePressState()->rightMouse = true;
DefWindowProc(hWnd, message, wParam, lParam);
break;
case WM_RBUTTONUP:
window->getMousePressState()->rightMouse = false;
DefWindowProc(hWnd, message, wParam, lParam);
break;
case WM_MBUTTONDOWN:
window->getMousePressState()->middleMouse = true;
DefWindowProc(hWnd, message, wParam, lParam);
break;
case WM_MBUTTONUP:
window->getMousePressState()->middleMouse = false;
DefWindowProc(hWnd, message, wParam, lParam);
break;
case WM_DESTROY:
window->Destroy();
PostQuitMessage(0);
window->displayState = 0;
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}