diff --git a/include/window.hpp b/include/window.hpp index 5cf1fd80..c19733d8 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -38,6 +38,7 @@ void windowCursorLock(); void windowCursorUnlock(); bool windowIsModPressed(); bool windowIsShiftPressed(); +bool windowIsKeyPressed(int key); Vec windowGetWindowSize(); void windowSetWindowSize(Vec size); Vec windowGetWindowPos(); diff --git a/src/app/Knob.cpp b/src/app/Knob.cpp index 4eb0a522..c57a191d 100644 --- a/src/app/Knob.cpp +++ b/src/app/Knob.cpp @@ -1,8 +1,6 @@ #include "app.hpp" #include "window.hpp" #include "engine.hpp" -// For GLFW_KEY_LEFT_CONTROL, etc. -#include namespace rack { diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 4fd88670..7eecc193 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -220,7 +220,7 @@ void ModuleWidget::onMouseMove(EventMouseMove &e) { // Don't delete the ModuleWidget if a TextField is focused if (!gFocusedWidget) { // Instead of checking key-down events, delete the module even if key-repeat hasn't fired yet and the cursor is hovering over the widget. - if (glfwGetKey(gWindow, GLFW_KEY_DELETE) == GLFW_PRESS || glfwGetKey(gWindow, GLFW_KEY_BACKSPACE) == GLFW_PRESS) { + if (windowIsKeyPressed(GLFW_KEY_DELETE) || windowIsKeyPressed(GLFW_KEY_BACKSPACE)) { if (!windowIsModPressed() && !windowIsShiftPressed()) { gRackWidget->deleteModule(this); this->finalizeEvents(); @@ -361,4 +361,4 @@ Menu *ModuleWidget::createContextMenu() { } -} // namespace rack \ No newline at end of file +} // namespace rack diff --git a/src/ui/ScrollWidget.cpp b/src/ui/ScrollWidget.cpp index dee321d9..579d907f 100644 --- a/src/ui/ScrollWidget.cpp +++ b/src/ui/ScrollWidget.cpp @@ -118,16 +118,16 @@ void ScrollWidget::onMouseMove(EventMouseMove &e) { else if (windowIsModPressed()) arrowSpeed /= 4.0; - if (glfwGetKey(gWindow, GLFW_KEY_LEFT) == GLFW_PRESS) { + if (windowIsKeyPressed(GLFW_KEY_LEFT)) { offset.x -= arrowSpeed; } - if (glfwGetKey(gWindow, GLFW_KEY_RIGHT) == GLFW_PRESS) { + if (windowIsKeyPressed(GLFW_KEY_RIGHT)) { offset.x += arrowSpeed; } - if (glfwGetKey(gWindow, GLFW_KEY_UP) == GLFW_PRESS) { + if (windowIsKeyPressed(GLFW_KEY_UP)) { offset.y -= arrowSpeed; } - if (glfwGetKey(gWindow, GLFW_KEY_DOWN) == GLFW_PRESS) { + if (windowIsKeyPressed(GLFW_KEY_DOWN)) { offset.y += arrowSpeed; } } diff --git a/src/ui/TextField.cpp b/src/ui/TextField.cpp index 765cd18b..90a843fe 100644 --- a/src/ui/TextField.cpp +++ b/src/ui/TextField.cpp @@ -1,8 +1,6 @@ #include "ui.hpp" // for gVg #include "window.hpp" -// for key codes -#include namespace rack { diff --git a/src/window.cpp b/src/window.cpp index bb72888f..cffff6c0 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -518,6 +518,10 @@ bool windowIsShiftPressed() { return glfwGetKey(gWindow, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(gWindow, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS; } +bool windowIsKeyPressed(int key) { + return glfwGetKey(gWindow, key) == GLFW_PRESS; +} + Vec windowGetWindowSize() { int width, height; glfwGetWindowSize(gWindow, &width, &height);