views:

192

answers:

1

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?

A: 

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.

Dala