.net - Simulate Keyboard Event -
i trying insert string values third party application say, notepad. below code using
[dllimport("user32.dll")] static extern void keybd_event(byte bvk, byte bscan, uint dwflags, uintptr dwextrainfo); public void sim_type(string txt) { const int keyeventf_extendedkey = 0x1; const int keyeventf_keyup = 0x2; byte[] asciivalues = encoding.ascii.getbytes(txt); foreach (byte keycode in asciivalues) { console.writeline("ascii values = " + keycode); keybd_event(keycode, 0x45, keyeventf_extendedkey, (uintptr)0); keybd_event(keycode, 0x45, keyeventf_extendedkey | keyeventf_keyup, (uintptr)0); } }
i giving sample text message example "this test message". getting proper ascii values. in target text box corresponding sample message getting output.
t89 9 1 13:38 02/12/2010513:38 02/12/2010 -5175
could 1 solve this. putting ascii values printed in console
messsage :this test message
{
ascii values = 84ascii values = 104
ascii values = 105
ascii values = 115
ascii values = 32
ascii values = 105
ascii values = 115
ascii values = 32
ascii values = 97
ascii values = 32
ascii values = 116
ascii values = 101
ascii values = 115
ascii values = 116
ascii values = 32
ascii values = 109
ascii values = 101
ascii values = 115
ascii values = 115
ascii values = 97
ascii values = 103
ascii values = 101
}
please thanks, nikil
keybd_event has been superseded sendinput. recommend taking @ windows input simulator provides nice c# wrapper around send input api. can simulate mouse movements sendinput api (and believe they're working on next version of input simulator).
i've used library automation project , seems work pretty well, there quirks (ie keystoke home + shift + end not select text expected).
Comments
Post a Comment