Here are some examples :
Code: Select all
//clicks at the current position
call mouse click
//double clicks at the current position
call mouse doubleClick
//right clicks at the current position
call mouse rightClick
//returns the position of the cursor
call mouse position
//scrolls up the mouse wheel with 1500 units
call mouse scrollUp 150
//scrolls down with 100 postitions
call mouse scrollDown 100
//relatively(from the current position) moves the mouse with 100 horizontal and 100 vertial postitions
call mouse moveBy 100x100
//absolute positioning
call mouse moveTo 100x100
//relative drag (leftclick and move)
call mouse dragBy 300x200
//absolute drag
call mouse dragTo 500x500
May be a little explanation is needed?
C# and VB allows direct access to native functions with DLLExport attribute - you need to know the function name ,its argument types and then you can use it.
So far it looks straight forward . First obstacle is the marshaling - the datatypes could vary between 32b and 64b machines and as a whole windows uses strange custom data types not specific for c/c++.
Here's a you can see how need to map your data types -
Code: Select all
https://msdn.microsoft.com/en-us/library/fzhhdwae(v=vs.110).aspx
usually the documentation what you'll need you can find in msdn. For the mouse.bat most important was the SendInput function
Code: Select all
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx
Often in windows APIs a whole structures are used as arguments and you'll need to create/marshal a composite datatypes which according to me could be most difficult part in calling native functions from C#.
And also often there's a passing by reference instead of returning object (I suppose this improves the performance as eliminates the need of creating a whole new object to be returned)
Here's a whole library that wraps user32.dll (this where keyboard and mouse functions are located) :
Code: Select all
https://inputsimulator.codeplex.com/
Elegant written and flexible though for hackish scripts like the mouse.bat I need single file solutions...