Skip to content

Commit

Permalink
Fix ion keyboard issue numworks#2235
Browse files Browse the repository at this point in the history
  • Loading branch information
mensheng-git committed Sep 28, 2024
1 parent 9072ab8 commit 48133e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
21 changes: 19 additions & 2 deletions ion/src/simulator/shared/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ State scan() {
}
#endif

#if __EMSCRIPTEN__
// Register a key for simulator keyboard
Key k = Simulator::Keyboard::getActiveKey();
if (k != Key::None) {
state.setKey(k);
}
#endif

// Catch the physical keyboard events
const uint8_t* SDLstate = SDL_GetKeyboardState(NULL);
for (int i = 0; i < sNumberOfKeyPairs; i++) {
Expand All @@ -100,9 +108,18 @@ namespace Ion {
namespace Simulator {
namespace Keyboard {

void keyDown(Ion::Keyboard::Key k) { Queue::sharedQueue()->push(State(k)); }
static Ion::Keyboard::Key sActiveKey = Ion::Keyboard::Key::None;
Ion::Keyboard::Key getActiveKey() { return sActiveKey ; }

void keyUp(Ion::Keyboard::Key k) { Queue::sharedQueue()->push(State(0)); }
void keyDown(Ion::Keyboard::Key k) {
Ion::Keyboard::pushState(State(k));
sActiveKey = k;
}

void keyUp(Ion::Keyboard::Key k) {
Queue::sharedQueue()->push(State(0));
sActiveKey = Ion::Keyboard::Key::None;
}

bool scanHandlesSDLKey(SDL_Scancode key) {
for (int i = 0; i < sNumberOfKeyPairs; i++) {
Expand Down
1 change: 1 addition & 0 deletions ion/src/simulator/shared/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Ion {
namespace Simulator {
namespace Keyboard {

Ion::Keyboard::Key getActiveKey();
void keyDown(Ion::Keyboard::Key k);
void keyUp(Ion::Keyboard::Key k);
bool scanHandlesSDLKey(SDL_Scancode key);
Expand Down

0 comments on commit 48133e7

Please sign in to comment.