c# - how to fire a keydown or keypress event -


i want key press event fire without pressing key user. use

inputsimulator.simulatekeypress(virtualkeycode.vk_u); 

also

system.windows.forms.sendkeys.send("a"); 

that did not cause use

    var key = key.insert;                    // key send     var target = keyboard.focusedelement;    // target element     var routedevent = keyboard.keydownevent; // event send      target.raiseevent(       new keyeventargs(         keyboard.primarydevice,         presentationsource.fromvisual(target),         0,         key) { routedevent = routedevent }     ); 

that make following error the name 'key' not exist in current context use

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.runtime.interopservices; using system.globalization; using system.windows.input; using windowsinput;  

and write codes on form1_load

@idle_mind thanks. works.

posting comment answer:

and write codes on form1_load

the load() event occurs before form has been displayed, therefore keystroke(s) being sent whatever application had focus right before program run (probably visual studio if you're running ide)

move test code shown() event , might better results...


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -