Skip to content

Commit

Permalink
modified GLFW engine to handle key modifers (e.g., Shift, Ctrl, Cmd) …
Browse files Browse the repository at this point in the history
…in a single key press; greatly improves typing speed
  • Loading branch information
adcox committed Jul 21, 2016
1 parent 39e1f2f commit cae9060
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/EngineGLFW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ void EngineGLFW::setup()
// Override listeners
ofAddListener(ofEvents().mousePressed, this, &EngineGLFW::onMousePressed);
ofAddListener(ofEvents().keyReleased, this, &EngineGLFW::onKeyReleased);

ofAddListener(ofEvents().keyPressed, this, &EngineGLFW::onKeyPressed);

// BaseEngine listeners
ofAddListener(ofEvents().keyPressed, (BaseEngine*)this, &BaseEngine::onKeyPressed);
ofAddListener(ofEvents().mouseDragged, (BaseEngine*)this, &BaseEngine::onMouseDragged);
ofAddListener(ofEvents().mouseReleased, (BaseEngine*)this, &BaseEngine::onMouseReleased);
ofAddListener(ofEvents().mouseScrolled, (BaseEngine*)this, &BaseEngine::onMouseScrolled);
Expand All @@ -66,9 +66,9 @@ void EngineGLFW::exit()
// Override listeners
ofRemoveListener(ofEvents().mousePressed, this, &EngineGLFW::onMousePressed);
ofRemoveListener(ofEvents().keyReleased, this, &EngineGLFW::onKeyReleased);
ofRemoveListener(ofEvents().keyPressed, this, &EngineGLFW::onKeyPressed);

// Base class listeners
ofRemoveListener(ofEvents().keyPressed, (BaseEngine*)this, &BaseEngine::onKeyPressed);
ofRemoveListener(ofEvents().mouseDragged, (BaseEngine*)this, &BaseEngine::onMouseDragged);
ofRemoveListener(ofEvents().mouseReleased, (BaseEngine*)this, &BaseEngine::onMouseReleased);
ofRemoveListener(ofEvents().mouseScrolled, (BaseEngine*)this, &BaseEngine::onMouseScrolled);
Expand Down Expand Up @@ -290,6 +290,19 @@ void EngineGLFW::onKeyReleased(ofKeyEventArgs& event)
io.KeyCtrl = io.KeysDown[GLFW_KEY_LEFT_CONTROL] || io.KeysDown[GLFW_KEY_RIGHT_CONTROL];
io.KeyShift = io.KeysDown[GLFW_KEY_LEFT_SHIFT] || io.KeysDown[GLFW_KEY_RIGHT_SHIFT];
io.KeyAlt = io.KeysDown[GLFW_KEY_LEFT_ALT] || io.KeysDown[GLFW_KEY_RIGHT_ALT];
io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER];
}

void EngineGLFW::onKeyPressed(ofKeyEventArgs& event){
int key = event.keycode;
ImGuiIO& io = ImGui::GetIO();
io.KeysDown[key] = true;

io.KeyCtrl = io.KeysDown[GLFW_KEY_LEFT_CONTROL] || io.KeysDown[GLFW_KEY_RIGHT_CONTROL];
io.KeyShift = io.KeysDown[GLFW_KEY_LEFT_SHIFT] || io.KeysDown[GLFW_KEY_RIGHT_SHIFT];
io.KeyAlt = io.KeysDown[GLFW_KEY_LEFT_ALT] || io.KeysDown[GLFW_KEY_RIGHT_ALT];
io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER];

if(key < GLFW_KEY_ESCAPE)
{
io.AddInputCharacter((unsigned short)event.codepoint);
Expand Down
1 change: 1 addition & 0 deletions src/EngineGLFW.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class EngineGLFW : public BaseEngine
bool createFontsTexture();

void onKeyReleased(ofKeyEventArgs& event) override;
void onKeyPressed(ofKeyEventArgs& event) override;
void onMousePressed(ofMouseEventArgs& event) override;

// Custom
Expand Down

0 comments on commit cae9060

Please sign in to comment.