question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyUp / KeyDown KeyEventHandler Queued

See original GitHub issue
public KeyCapture()
{
      Tick += new EventHandler(OnTick);

      KeyDown += OnKeyDown;
}

OnKeyDown { Camera(); }

OnTick {  if (IsControlJustReleased) { Camera(); }   }

Camera
{
     Screen.Message("Start"); KeyCapture.Wait( 5000 ); Screen.Message("End");
}

The above being a very basic example… not exact code just the layout 😃

Pressing the Control pad button repeatedly will Start a message only if a Press occurs after the Wait. Pressing the Keyboard key will stack up requests to the KeyEventHandler. Once the Wait releases they then begin to execute the queued commands even through the KeyPress was several seconds ago.

This is not the behaviour id expect so… is this a Bug or is there a work around i can use to dispose of the events when the script is not active ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RainerHilmercommented, Jul 18, 2017

Thank you for telling about the Handled property. I didn’t even know about it. LOL

1reaction
Tanjitsucommented, Jul 18, 2017

Thank you again RainerHilmer, i have added a simple solution that works so far 😃

public class KeyFilter : Script
{
        public KeyFilter()
        {
            KeyDown += OnKey;
        }

        private void OnKey(object sender, KeyEventArgs e)
        {
            KeyFilter.Yield();

            if (e != null && !e.Handled) e.Handled = true;
        }
}

I can then handle the keyEvents as normal in my KeyCapture script but just check if (!e.Handled). While my main script KeyCapture is waiting KeyFilter will flag any keyEvents as handled.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Capturing KeyDown events in a UserControl
I registered the KeyDown-event handler of the main window in my user control. this.Parent.KeyDown += new KeyEventHandler(MyControl_KeyDown);.
Read more >
Chapter 14 Handling Events
A program can then periodically check the queue for new events and react to ... The "keydown" and "keyup" events give you information...
Read more >
Modify keyboard key events - Windows Forms .NET
Consume a key. In a KeyPress event handler, set the Handled property of the KeyPressEventArgs class to true . -or-. In a KeyDown...
Read more >
Clearing KeyPress Queue - wxWidgets Discussion Forum
Right now, I'm using the timer event loop from the previous link. My current problem is figuring out how to use keyboard input...
Read more >
Managing User Input Key-Events Across Views In AngularJS
The keyEvents service maintains an internal queue of event handlers that are sorted based on priority. Then, when a key-event is triggered, the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found