Automating keydown (or any eventhandlers)

In addition to my previous query, I was wondering if it is possible to automate the keydown function (for debugging purposes)?

My thanks in advance!

Create the code you’d like to call anytime as a Method. Call the method from the Event Handler. When debugging, call the method from however you’re debugging it.

2 Likes

Thank you for the response!

However, I do not think this entirely addresses my question which may require some clarification.

I would like to use a method to automatically initiate a keydown press without actually pressing the key. In other words, I’d like to write a code in the methods that tricks the computer into thinking a key was pressed (or any event was activated). Is this possible? Also, it is imperative that the code works in a way that it operates through a keydown event handler.

Take this design:

And then call HandleKeyDown with whatever method you’re using to debug like in the Action event of a Button.

This is a common method to make debugging event handlers easier.

2 Likes
  1. It is still technically possible to persuade the OS to pass on faux keydown events to applications. However it is much harder to do now, because this is considered a “Security” risk.
  2. Tim is providing a solution that you can implement in your application without having to deal with the ever changing “Security” issues. It will however only work on your application.
3 Likes

Thank you both for the replies!

I think I understand how this solution works and it is very helpful and closer to what I am looking for. But I fear that I am still being unclear with what I am looking for (I’m sorry!).

What I am trying to do is create a loop where a button is automatically pressed at random time intervals. The overall program I am creating is one where I record people’s response time (time to press a button) when a certain image is shown. However, past data showed that the program was unable to record response times at when a certain number of time had passed, or rather, recorded that a button was pressed after this block of time. For example, if someone pressed a button after 200 msecs, the program did not record that the button was pressed at 200 msec and recorded that a button was pressed at 220 (see example). Therefore, I currently want to test this program’s ability to record the time that a button was pressed at any given time but automate this button press event.


(X axis is response time, y axis is number of times pressed).
p.s. I’m sorry if I am being unclear and difficult. I appreciate everyone taking the time to help!