0
votes

I have a winforms application where I need to capture keyboard input and store it in a script. The script can then be replayed with IronPython to automate the application. My current take on this is to listen on KeyPress events and resend the pressed character with SendKeys.Send(). To handle input with modifiers (alt, ctrl) I listen to the KeyDown event but here I don't know how to represent the keys pressed in the script. This is what I would like to do:

public void TextBox_KeyDown(KeyEventArgs e)
{
    Script.AddStatement(string.Format("SendKeys.Send('{0}')", ????));
}

Do I manually have to create a string from KeyEventArgs that SendKeys understands?
Eg shift+A, shift+B becomes SendKeys.Send("+(AB)"). Details from MSDN.

Is there another way? Maybe to store the KeyEventArgs.KeyData and create a new KeyEventArgs instance and send that somehow?

1
What kind of type is the Script?Peter Gfader
What is SendKeys.Send() expecting as parameter? Maybe (char)e.KeyCode is already good to go...Peter Gfader

1 Answers

0
votes

The answer to this question was to stop using SendKeys and instead use p/invoke of keybd_event. SendKeys has timing issues and other unexcpected behavior.