jasonpang / Interceptor

C# wrapper for a Windows keyboard driver. Can simulate keystrokes and mouse clicks in protected areas like the Windows logon screen (and yes, even in games). Wrapping http://oblita.com/Interception
MIT License
286 stars 84 forks source link

About does not function reliably and often moves the mouse in unpredictable vectors. #9

Open tomby opened 6 years ago

tomby commented 6 years ago

I had a deep study on C++ sample source and found all the location(mean x,y) changed to device location such as int x = static_cast((0xFFFF (center.x + position.x)) / screen_width); This means the X and y which is passed to the two function MoveMouseTo and MoveMouseBy are not correctly or unclear. So I did some change, it works perfectly. here is my change: Point point = ConvertDevicePoint(x, y); mouseStroke.X = point.X; mouseStroke.Y = point.Y; The function ConvertDevicePoint code is the following: ` private static Point ConvertDevicePoint(int x,int y) { int SH = Screen.PrimaryScreen.Bounds.Height; int SW = Screen.PrimaryScreen.Bounds.Width; return new Point(0xFFFF x / SW, 0xFFFF * y / SH); } ` Then it works.

Thanks a lot for your code and help me a lot.

barak1413 commented 6 years ago

You succeed to simulate left and right click? The keyboard works great in contrast to the mouse that doesn't work at all.

tomby commented 6 years ago

Yes,it works correctly by the way aboved

hoanglong241231 commented 4 years ago

I try your solution but, it still move the mouse to wrong location, for example: I have 2 monitors 1920x1080, if I use MoveMouseto(1300,700) - that is definitely inside the 1st monitor but it move the mouse to 2nd monitor and even wrong coordinate rather than 1300, 700.

hoanglong241231 commented 4 years ago

Im repying to aswer my own question. If you have 2 monitors that have same resolution and their position (in side window display setting) is placed same row, like 2 x 1920*1080 You may want to try to devide the 0xFFFF by 2. if 2 monitor is placed same row then in the X, devide 0xFFFF by 2, and keep 0xFFFF of the Y. if 2 monitor is placed same column then in the Y, devide 0xFFFF by 2, and keep 0xFFFF of the X. You may want to make further maths if your case is 2 monitors have different res, or more than 2 monitors,... etc

tomby commented 4 years ago

Im repying to aswer my own question. If you have 2 monitors that have same resolution and their position (in side window display setting) is placed same row, like 2 x 1920*1080 You may want to try to devide the 0xFFFF by 2. if 2 monitor is placed same row then in the X, devide 0xFFFF by 2, and keep 0xFFFF of the Y. if 2 monitor is placed same column then in the Y, devide 0xFFFF by 2, and keep 0xFFFF of the X. You may want to make further maths if your case is 2 monitors have different res, or more than 2 monitors,... etc

It's up to your main monitor, please make sure the master and slave monitor is correct.