diff --git a/Windows/Debugger/CtrlDisAsmView.cpp b/Windows/Debugger/CtrlDisAsmView.cpp index 7b9d557e79..8943335492 100644 --- a/Windows/Debugger/CtrlDisAsmView.cpp +++ b/Windows/Debugger/CtrlDisAsmView.cpp @@ -806,7 +806,7 @@ void CtrlDisAsmView::onKeyDown(WPARAM wParam, LPARAM lParam) u32 windowEnd = windowStart+visibleRows*instructionSize; keyTaken = true; - if (GetAsyncKeyState(VK_CONTROL)) + if (KeyDownAsync(VK_CONTROL)) { switch (tolower(wParam & 0xFFFF)) { @@ -840,28 +840,28 @@ void CtrlDisAsmView::onKeyDown(WPARAM wParam, LPARAM lParam) switch (wParam & 0xFFFF) { case VK_DOWN: - setCurAddress(curAddress + instructionSize, GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(curAddress + instructionSize, KeyDownAsync(VK_SHIFT)); scrollAddressIntoView(); break; case VK_UP: - setCurAddress(curAddress - instructionSize, GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(curAddress - instructionSize, KeyDownAsync(VK_SHIFT)); scrollAddressIntoView(); break; case VK_NEXT: if (curAddress != windowEnd - instructionSize && curAddressIsVisible()) { - setCurAddress(windowEnd - instructionSize, GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(windowEnd - instructionSize, GetAsyncKeyState(VK_SHIFT)); scrollAddressIntoView(); } else { - setCurAddress(curAddress + visibleRows * instructionSize, GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(curAddress + visibleRows * instructionSize, KeyDownAsync(VK_SHIFT)); scrollAddressIntoView(); } break; case VK_PRIOR: if (curAddress != windowStart && curAddressIsVisible()) { - setCurAddress(windowStart, GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(windowStart, KeyDownAsync(VK_SHIFT)); scrollAddressIntoView(); } else { - setCurAddress(curAddress - visibleRows * instructionSize, GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(curAddress - visibleRows * instructionSize, KeyDownAsync(VK_SHIFT)); scrollAddressIntoView(); } break; @@ -961,7 +961,7 @@ void CtrlDisAsmView::onMouseDown(WPARAM wParam, LPARAM lParam, int button) int y = HIWORD(lParam); u32 newAddress = yToAddress(y); - bool extend = GetAsyncKeyState(VK_SHIFT) != 0; + bool extend = KeyDownAsync(VK_SHIFT); if (button == 1) { if (newAddress == curAddress && hasFocus) @@ -987,7 +987,7 @@ void CtrlDisAsmView::onMouseUp(WPARAM wParam, LPARAM lParam, int button) { int x = LOWORD(lParam); int y = HIWORD(lParam); - setCurAddress(yToAddress(y), GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(yToAddress(y), KeyDownAsync(VK_SHIFT)); redraw(); } else if (button == 2) @@ -1154,7 +1154,7 @@ void CtrlDisAsmView::onMouseMove(WPARAM wParam, LPARAM lParam, int button) { int x = LOWORD(lParam); int y = HIWORD(lParam); - setCurAddress(yToAddress(y), GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(yToAddress(y), KeyDownAsync(VK_SHIFT)); // TODO: Perhaps don't do this every time, but on a timer? redraw(); } @@ -1289,7 +1289,7 @@ void CtrlDisAsmView::search(bool continueSearch) } // cancel search - if ((searchAddress % 256) == 0 && GetAsyncKeyState(VK_ESCAPE)) + if ((searchAddress % 256) == 0 && KeyDownAsync(VK_ESCAPE)) { searching = false; return; diff --git a/Windows/Debugger/CtrlMemView.cpp b/Windows/Debugger/CtrlMemView.cpp index d737cf637d..1554a9cf0b 100644 --- a/Windows/Debugger/CtrlMemView.cpp +++ b/Windows/Debugger/CtrlMemView.cpp @@ -302,7 +302,7 @@ void CtrlMemView::onVScroll(WPARAM wParam, LPARAM lParam) void CtrlMemView::onKeyDown(WPARAM wParam, LPARAM lParam) { - if (GetAsyncKeyState(VK_CONTROL)) + if (KeyDownAsync(VK_CONTROL)) { switch (tolower(wParam & 0xFFFF)) { @@ -354,7 +354,7 @@ void CtrlMemView::onKeyDown(WPARAM wParam, LPARAM lParam) void CtrlMemView::onChar(WPARAM wParam, LPARAM lParam) { - if (GetAsyncKeyState(VK_CONTROL) || wParam == VK_TAB) return; + if (KeyDownAsync(VK_CONTROL) || wParam == VK_TAB) return; if (!Memory::IsValidAddress(curAddress)) { @@ -649,12 +649,12 @@ void CtrlMemView::search(bool continueSearch) while (index < endIndex) { // cancel search - if ((index % 256) == 0 && GetAsyncKeyState(VK_ESCAPE)) + if ((index % 256) == 0 && KeyDownAsync(VK_ESCAPE)) { searching = false; return; } - + if (memcmp(&dataPointer[index],searchData.data(),searchData.size()) == 0) { matchAddress = index+segmentStart; diff --git a/Windows/GEDebugger/CtrlDisplayListView.cpp b/Windows/GEDebugger/CtrlDisplayListView.cpp index 02ed013c8c..cd3c9ae7d9 100644 --- a/Windows/GEDebugger/CtrlDisplayListView.cpp +++ b/Windows/GEDebugger/CtrlDisplayListView.cpp @@ -264,7 +264,7 @@ void CtrlDisplayListView::onMouseDown(WPARAM wParam, LPARAM lParam, int button) int line = y/rowHeight; u32 newAddress = windowStart + line*instructionSize; - bool extend = GetAsyncKeyState(VK_SHIFT) != 0; + bool extend = KeyDownAsync(VK_SHIFT); if (button == 1) { if (newAddress == curAddress && hasFocus) @@ -412,28 +412,28 @@ void CtrlDisplayListView::onKeyDown(WPARAM wParam, LPARAM lParam) switch (wParam & 0xFFFF) { case VK_DOWN: - setCurAddress(curAddress + instructionSize, GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(curAddress + instructionSize, KeyDownAsync(VK_SHIFT)); scrollAddressIntoView(); break; case VK_UP: - setCurAddress(curAddress - instructionSize, GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(curAddress - instructionSize, KeyDownAsync(VK_SHIFT)); scrollAddressIntoView(); break; case VK_NEXT: if (curAddress != windowEnd - instructionSize && curAddressIsVisible()) { - setCurAddress(windowEnd - instructionSize, GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(windowEnd - instructionSize, KeyDownAsync(VK_SHIFT)); scrollAddressIntoView(); } else { - setCurAddress(curAddress + visibleRows * instructionSize, GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(curAddress + visibleRows * instructionSize, KeyDownAsync(VK_SHIFT)); scrollAddressIntoView(); } break; case VK_PRIOR: if (curAddress != windowStart && curAddressIsVisible()) { - setCurAddress(windowStart, GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(windowStart, KeyDownAsync(VK_SHIFT)); scrollAddressIntoView(); } else { - setCurAddress(curAddress - visibleRows * instructionSize, GetAsyncKeyState(VK_SHIFT) != 0); + setCurAddress(curAddress - visibleRows * instructionSize, KeyDownAsync(VK_SHIFT)); scrollAddressIntoView(); } break; diff --git a/Windows/W32Util/Misc.h b/Windows/W32Util/Misc.h index 03f121066f..8189a7e20d 100644 --- a/Windows/W32Util/Misc.h +++ b/Windows/W32Util/Misc.h @@ -17,6 +17,14 @@ struct GenericListViewColumn float size; }; +// the most significant bit states whether the key is currently down. +// simply checking if it's != 0 is not enough, as bit0 is set if +// the key was pressed between the last call to GetAsyncKeyState +inline bool KeyDownAsync(int vkey) +{ + return (GetAsyncKeyState(vkey) & 0x8000) != 0; +} + class GenericListControl { public: