background - How to send mouse events to a minimized form in c#? -


i try write simple tester tool, testing web site (win form, using webbrowser control). need send mouse click , keystrokes site. works when form on top, run tester in background. how can send mouse click, keystrokes minimized/background form? current mouse event code:

[dllimport( "user32.dll", charset = charset.auto, callingconvention = callingconvention.stdcall )] public static extern void mouse_event( uint dwflags, uint dx, uint dy, uint cbuttons, uintptr dwextrainfo );  [flags] public enum mouseeventflags {     leftdown = 0x00000002,     leftup = 0x00000004,     middledown = 0x00000020,     middleup = 0x00000040,     move = 0x00000001,     absolute = 0x00008000,     rightdown = 0x00000008,     rightup = 0x00000010 }  void mouseevent( uint flag, point p ) {     p = caller.pointtoscreen( p );      cursor.position = p;     mouse_event( flag, (uint) 0, (uint) 0, (uint) 0, (uintptr) 0 ); } public void sendmouseclick( point p ) {     uint flag = (uint) mouseeventflags.leftdown + (uint) mouseeventflags.leftup;      mouseevent( flag, p ); } 

-- edited:

i tried sendmessage didn't works :( try use simple 2 buttons, no web browser, normal windows.form , buttons. try click button1 code when push button2. :)

        // on form, when press button 2 minimize, wait, , try press button1     private void button2_click( object sender, eventargs e)     {         // this.raisemouseevent();         mousehelper mh = new mousehelper(this.text);         this.windowstate = formwindowstate.minimized;         thread.sleep( 2000 );         this.refresh();         thread.sleep(2000);         mh.sendmouseclick( 25,25 );     }      private void button1_click( object sender, eventargs e )     {         throw new exception( "button 1 clicked" );     }      // in mousehelper call left click     public void sendmouseclick( int p_x, int p_y )     {         int32 l_parm1 = (p_y << 16) | (p_x & 0xffff);         sendmessage( windowptr, wm_lbuttondown, 0, l_parm1 );         sendmessage( windowptr, wm_lbuttonup, 0, l_parm1 );     }      public mousehelper( string windowtitle )     {         windowptr = findwindowbycaption( intptr.zero, windowtitle );     }      // defintions     public const uint wm_lbuttondown = 0x0201;     public const uint wm_lbuttonup = 0x0202;      [dllimport( "user32.dll", charset = charset.auto, callingconvention = callingconvention.stdcall )]     public static extern int sendmessage(         intptr hwnd,         uint msg,         int32 wparam,         int32 lparam     ); 

what did wrong?

it doesn't work window not minimezed:( 1st solution works when window active, 2nd not :( tried 25,25 , 147,47 (result of pointoscreen of 25,25)

probably sendmessage work. see sendmessage , system defined messages (more here)

something like:

sendmessage(hwnd, wm_lbuttondown, 0, (123<<16)|(456)); sendmessage(hwnd, wm_lbuttonup, 0, (123<<16)|(456)); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -