Please please please please ...
-
... please please please please give me a working code sample that uses SendInput to SIMULATE the movement of a mouse on a x64 vista system: 1. move mouse to screen location 200,100 2. mouse down 3. move the mouse down 12 (to 200,112) 4. mouse up it seems like such a trivial task but is clearly one that i have not been able to master. i have searched the internet high and low, found a gazillion articles on the subject, tried 9 different samples (all failed), and have spent a minimum of 100 hours on this problem. I've learned a lot but the idea of running 32-bit DLL's on a 64-bit computer is still way over my head ... i need help desperately. I have been able to get it to work using SetCursorPos and mouse_event but those methods actually steal the mouse from the user and make him VERY grumpy :) Thank you oh so VERY MUCH in advance!
-
... please please please please give me a working code sample that uses SendInput to SIMULATE the movement of a mouse on a x64 vista system: 1. move mouse to screen location 200,100 2. mouse down 3. move the mouse down 12 (to 200,112) 4. mouse up it seems like such a trivial task but is clearly one that i have not been able to master. i have searched the internet high and low, found a gazillion articles on the subject, tried 9 different samples (all failed), and have spent a minimum of 100 hours on this problem. I've learned a lot but the idea of running 32-bit DLL's on a 64-bit computer is still way over my head ... i need help desperately. I have been able to get it to work using SetCursorPos and mouse_event but those methods actually steal the mouse from the user and make him VERY grumpy :) Thank you oh so VERY MUCH in advance!
IceWater42 wrote:
1. move mouse to screen location 200,100 2. mouse down 3. move the mouse down 12 (to 200,112) 4. mouse up
Uhh, this is nice and all, but if the user is moving the mouse in the same window that this code is sending messages to, it'll fail to do what you want since the real mouse will be mixing in it's messages with yours. The only way to prevent that is to stop the user from using the mouse at all while you send your mouse messages. Again, a very ugly solution.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
... please please please please give me a working code sample that uses SendInput to SIMULATE the movement of a mouse on a x64 vista system: 1. move mouse to screen location 200,100 2. mouse down 3. move the mouse down 12 (to 200,112) 4. mouse up it seems like such a trivial task but is clearly one that i have not been able to master. i have searched the internet high and low, found a gazillion articles on the subject, tried 9 different samples (all failed), and have spent a minimum of 100 hours on this problem. I've learned a lot but the idea of running 32-bit DLL's on a 64-bit computer is still way over my head ... i need help desperately. I have been able to get it to work using SetCursorPos and mouse_event but those methods actually steal the mouse from the user and make him VERY grumpy :) Thank you oh so VERY MUCH in advance!
-
... please please please please give me a working code sample that uses SendInput to SIMULATE the movement of a mouse on a x64 vista system: 1. move mouse to screen location 200,100 2. mouse down 3. move the mouse down 12 (to 200,112) 4. mouse up it seems like such a trivial task but is clearly one that i have not been able to master. i have searched the internet high and low, found a gazillion articles on the subject, tried 9 different samples (all failed), and have spent a minimum of 100 hours on this problem. I've learned a lot but the idea of running 32-bit DLL's on a 64-bit computer is still way over my head ... i need help desperately. I have been able to get it to work using SetCursorPos and mouse_event but those methods actually steal the mouse from the user and make him VERY grumpy :) Thank you oh so VERY MUCH in advance!
hmm i think i tried using sendinput and found it sucked. I like using send message because you dont need to actually move the mouse about to click... you can send the coordinates of where a click is to occur... much more sexy right. Their might be problems or something with some windows and i think i had to have the window focused to get it to actually work.... unfortunatelly its not as nice as when doing sendmessage with keystrokes because in that case theirs no need to have the window focused... good for my bot... had it in the background doing stuff while i used the computer lol... anyway here's what i had for using sendmessage (i think i had code for sendinput and deleted it because while it worked, it required both focus of the window and ownership of the moues cursor):
using System; using System.Text; using System.Runtime.InteropServices; using System.Drawing; using System.Windows.Forms; using System.Threading; namespace MouseKeyboardLibrary { /// <summary> /// Operations that simulate mouse events /// </summary> public class MouseSimulatorMessenger { [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] private static extern int SetForegroundWindow(IntPtr hWnd); //const int MK_LBUTTON = 0x1; //const int MK_RBUTTON = 0x2; //const int MK_SHIFT = 0x4; //const int MK_CONTROL = 0x8; //const int MK_MBUTTON = 0x10; //const int MK_XBUTTON1 = 0x20; //const int MK_XBUTTON2 = 0x40; static IntPtr? handle = IntPtr.Zero; public IntPtr? Handle { get { return handle; } set { handle = value; } } #region Windows API Code //x -> loword //y -> hiword private static IntPtr MakeLParam(int LoWord, int HiWord) { return (IntPtr)((HiWord << 16) | (LoWord & 0xffff)); //Int32 lParam = x + y * 0x00010000 //return (IntPtr)(LoWord + HiWord * 0x00010000); } const int WM_LBUTTONDOWN = 0x0201; const int WM_LBUTTONUP = 0x0202; const int WM_MBUTTONDOWN = 0x207; const int WM_MBUTTONUP = 0x208; const int WM_RBUTTONDOWN = 0x0204; const int WM_RBUTTONUP = 0x0205; [return: MarshalAs(UnmanagedType.Bool)] [DllImport("user32.dll", SetLastError = true)] static extern bool SendMessageA(IntPtr hWn
-
hmm i think i tried using sendinput and found it sucked. I like using send message because you dont need to actually move the mouse about to click... you can send the coordinates of where a click is to occur... much more sexy right. Their might be problems or something with some windows and i think i had to have the window focused to get it to actually work.... unfortunatelly its not as nice as when doing sendmessage with keystrokes because in that case theirs no need to have the window focused... good for my bot... had it in the background doing stuff while i used the computer lol... anyway here's what i had for using sendmessage (i think i had code for sendinput and deleted it because while it worked, it required both focus of the window and ownership of the moues cursor):
using System; using System.Text; using System.Runtime.InteropServices; using System.Drawing; using System.Windows.Forms; using System.Threading; namespace MouseKeyboardLibrary { /// <summary> /// Operations that simulate mouse events /// </summary> public class MouseSimulatorMessenger { [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] private static extern int SetForegroundWindow(IntPtr hWnd); //const int MK_LBUTTON = 0x1; //const int MK_RBUTTON = 0x2; //const int MK_SHIFT = 0x4; //const int MK_CONTROL = 0x8; //const int MK_MBUTTON = 0x10; //const int MK_XBUTTON1 = 0x20; //const int MK_XBUTTON2 = 0x40; static IntPtr? handle = IntPtr.Zero; public IntPtr? Handle { get { return handle; } set { handle = value; } } #region Windows API Code //x -> loword //y -> hiword private static IntPtr MakeLParam(int LoWord, int HiWord) { return (IntPtr)((HiWord << 16) | (LoWord & 0xffff)); //Int32 lParam = x + y * 0x00010000 //return (IntPtr)(LoWord + HiWord * 0x00010000); } const int WM_LBUTTONDOWN = 0x0201; const int WM_LBUTTONUP = 0x0202; const int WM_MBUTTONDOWN = 0x207; const int WM_MBUTTONUP = 0x208; const int WM_RBUTTONDOWN = 0x0204; const int WM_RBUTTONUP = 0x0205; [return: MarshalAs(UnmanagedType.Bool)] [DllImport("user32.dll", SetLastError = true)] static extern bool SendMessageA(IntPtr hWn
Thank you so very much for your code and time. The MakeLParam code is especially cool. The most valuable info was actually your side comment: :laugh: (i think i had code for sendinput and deleted it because while it worked, it required both focus of the window and ownership of the moues cursor) :laugh: ... as that indeed makes SendInput a deal breaker. I have tried SendMessage, and it did work, but as i recall it too had some undesirable side-effects ... hence the desperate plea. Once again, thank you.
-
IceWater42 wrote:
1. move mouse to screen location 200,100 2. mouse down 3. move the mouse down 12 (to 200,112) 4. mouse up
Uhh, this is nice and all, but if the user is moving the mouse in the same window that this code is sending messages to, it'll fail to do what you want since the real mouse will be mixing in it's messages with yours. The only way to prevent that is to stop the user from using the mouse at all while you send your mouse messages. Again, a very ugly solution.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008yes ... i agree it is ugly. I think by now i have tried ALL the ugly ways of doing it. That is why i posted the plea for help ... i keep hoping for a prettier solution. Through trial-and-error these past 2 weeks, i have seen the ugly side-effects of many of the researched "solutions" ... none of which were very User-Friendly. Add in the complications of 64-bit hardware with 32-bit DLLs and (for me) the task is daunting. That is why i posted my plea ... i was hoping that there actually might be a reasonably good way to do it, and that one of the very creative people here would show me how. Maybe there still is a glimmer of hope, thanks to the time and effort of FocusedWolf, below.
-
yes ... i agree it is ugly. I think by now i have tried ALL the ugly ways of doing it. That is why i posted the plea for help ... i keep hoping for a prettier solution. Through trial-and-error these past 2 weeks, i have seen the ugly side-effects of many of the researched "solutions" ... none of which were very User-Friendly. Add in the complications of 64-bit hardware with 32-bit DLLs and (for me) the task is daunting. That is why i posted my plea ... i was hoping that there actually might be a reasonably good way to do it, and that one of the very creative people here would show me how. Maybe there still is a glimmer of hope, thanks to the time and effort of FocusedWolf, below.
IceWater42 wrote:
Maybe there still is a glimmer of hope, thanks to the time and effort of FocusedWolf, below.
Your only congratulating him becuase he wrote your entire project for you. Too bad too. You've skipped the part where you learn how Windows works internally. I've already found ways in which that code will break. When your users find them too, have fun trying to diagnose the problems and work around them.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Thank you so very much for your code and time. The MakeLParam code is especially cool. The most valuable info was actually your side comment: :laugh: (i think i had code for sendinput and deleted it because while it worked, it required both focus of the window and ownership of the moues cursor) :laugh: ... as that indeed makes SendInput a deal breaker. I have tried SendMessage, and it did work, but as i recall it too had some undesirable side-effects ... hence the desperate plea. Once again, thank you.
Here an assembly with everything :P http://wolfsfiles.googlepages.com/MouseKeyboardLibrary.zip[^] Basically it started out as some freely available one i found on the internet, and over time i've been rewriting parts of it to suit my needs... like it didn't come with the sendmessage stuff or the new sendinput stuff i wrote today... Anyways if your interested in trying out sendinput, for the mouse atlesat,... it's in there. Turns out when i said i tried the send input... it was probably the MouseEvent api i tried... nonetheless i saw it did the same behavior as i said... forcing the cursor to move to a position to click that position. Was fun to write that... lol SendInput even has compatibility issues with 64bit and 32bit that took a bit of googling to get around.
-
Here an assembly with everything :P http://wolfsfiles.googlepages.com/MouseKeyboardLibrary.zip[^] Basically it started out as some freely available one i found on the internet, and over time i've been rewriting parts of it to suit my needs... like it didn't come with the sendmessage stuff or the new sendinput stuff i wrote today... Anyways if your interested in trying out sendinput, for the mouse atlesat,... it's in there. Turns out when i said i tried the send input... it was probably the MouseEvent api i tried... nonetheless i saw it did the same behavior as i said... forcing the cursor to move to a position to click that position. Was fun to write that... lol SendInput even has compatibility issues with 64bit and 32bit that took a bit of googling to get around.
I was wondering if I could ask a silly question. Would it be possible to show an example of how to use the .dll with a Visual Basic app? I understand what it does and everything just never wrote anything is c# and needed a starting point for a VB app i wanted to play with.
-
I was wondering if I could ask a silly question. Would it be possible to show an example of how to use the .dll with a Visual Basic app? I understand what it does and everything just never wrote anything is c# and needed a starting point for a VB app i wanted to play with.
If by vb you mean vb.net, then it's really easy to do... just unpack the solution and copy it into your vb.net project... then go into visual studio, load your vb.net project, and then right click on your solution and click "Add Existing Project" and navigate to the project file in the dll project. After you do that, you have to go to your vb.net project, and expand the area called "References", and then a window pops up... click the "Project" tab... the c# project should be listed... add it. Now what this means is the classes in the c# project should be callable from the vb.net project (although i never tried it... but that functionality is said to exist :P). ---------------- If by vb you mean... old vb... not vb.net... then you'd have to rewrite all of the code to get it to work. I have no real experience with old vb so can't help with that :P