Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast short keypresses trigger OnKeyLongPress #18

Open
pre-martin opened this issue Oct 18, 2023 · 2 comments
Open

Fast short keypresses trigger OnKeyLongPress #18

pre-martin opened this issue Oct 18, 2023 · 2 comments

Comments

@pre-martin
Copy link

When a button is pressed repeatedly and faster than LongKeyPressInterval, the implementation of StreamDeckAction triggers falsely OnKeyLongPress.

The flow is as follows:

  1. Button is pressed
  2. OnKeyDown() puts the EventArgs on the stack and starts Task.Delay()
  3. Button is released
  4. OnKeyUp() successfully pops the EventArgs from the stack and thus calls OnKeyPress() (the callback for short keypress).
  5. Problem: The Task.Delay() is still active and waiting.
  6. Button is pressed again. This has to happen with 500ms after the first time that the button was pressed (or <= LongKeyPressInterval)
  7. OnKeyDown() puts the EventArgs on the stack
  8. Task.Delay() from the first button press finishes and successfully pops an event from the stack. Unfortunately, this is the event from the second button press and not from the first button press. In consequence, the callback OnKeyLongPresss() is getting called.

I think that TryHandleKeyPress() must also cancel Task.Delay() when it successfully popped an item from the stack.

@pre-martin
Copy link
Author

pre-martin commented Oct 18, 2023

Fix is easy by using a CancellationTokenSource. See https://github.com/pre-martin/StreamDeckSimHubPlugin/pull/76/files#diff-1e758b02ba044ebded4f7f775722fadaa5cceae3fda25bf1e4f09a43565244b8R46-R55 for a solution. The Delay is cancelled in TryHandlePress()

@pre-martin
Copy link
Author

The CancelationTokenSource has to be recreated. This has to be added to the fix from above: https://github.com/pre-martin/StreamDeckSimHubPlugin/pull/77/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant