.net - Emulating keyboard enter key in C# -
i trying emulate various tasks in win7 , have problems function :
leftmouseclick(cursor.position.x - 720, cursor.position.y - 45); system.threading.thread.sleep(1000); // simulate each key stroke inputsimulator.simulatekeydown(virtualkeycode.return); inputsimulator.simulatekeyup(virtualkeycode.return); inputsimulator.simulatetextentry("cmd"); system.threading.thread.sleep(1000); inputsimulator.simulatekeydown(virtualkeycode.return); inputsimulator.simulatekeyup(virtualkeycode.return);
all want press start, write cmd, hit enter. works smooth except hitting enter key.
all of happening on rdp activex, here code :
var client = (imsrdpclient7)rdp.getocx(); // client.remoteprogram2.remoteprogrammode = true; ((mstsclib.imsrdpclientadvancedsettings5)rdp.advancedsettings).displayconnectionbar = true; ((mstsclib.imsrdpclientadvancedsettings5)rdp.advancedsettings).connectionbarshowpinbutton = true; ((mstsclib.imsrdpclientadvancedsettings5)rdp.advancedsettings).bitmapvirtualcache32bppsize = 48; ((mstsclib.imsrdpclientadvancedsettings5)rdp.advancedsettings).connectionbarshowrestorebutton = false; ((mstsclib.imsrdpclientadvancedsettings5)rdp.advancedsettings).connectionbarshowminimizebutton = true; ((mstsclib.imsrdpclientadvancedsettings5)rdp.advancedsettings).enablewindowskey = 1; ((mstsclib.imsrdpclientadvancedsettings5)rdp.advancedsettings).grabfocusonconnect = true; ((mstsclib.imsrdpclientadvancedsettings5)rdp.advancedsettings).redirectdrives = true; ((mstsclib.imsrdpclientadvancedsettings5)rdp.advancedsettings).redirectclipboard = true; ((mstsclib.imsrdpclientadvancedsettings5)rdp.advancedsettings).redirectprinters = true; ((mstsclib.imsrdpclientadvancedsettings5)rdp.advancedsettings).redirectposdevices = true; rdp.server = "1.2.3.4"; rdp.username = "rmlabuser2"; imstscnonscriptable secured = (imstscnonscriptable)rdp.getocx(); secured.cleartextpassword = "rmlabuser2"; // rdp.fullscreentitle = "full screen"; // rdp.securedsettings.fullscreen = 1; // rdp.securedsettings.startprogram = "calc"; rdp.connect();
i repeat, keys works, cannot hit enter.
thanks.
you try p/invoking windows's keybd_event
method instead.
[dllimport("user32.dll")] static extern void keybd_event(byte bvk, byte bscan, uint dwflags, int dwextrainfo); const uint keyeventf_extendedkey = 0x0001; const uint keyeventf_keyup = 0x0002;
then when want press it:
keybd_event((byte)system.windows.forms.keys.enter, 0x45, keyeventf_extendedkey, 0); //key down keybd_event((byte)system.windows.forms.keys.enter, 0x45, keyeventf_extendedkey |keyeventf_keyup, 0); //key
Comments
Post a Comment