add drag and move mouse multiple screens support

This commit is contained in:
vcaesar 2019-11-30 14:28:38 -04:00
parent a3da8915b9
commit 4df22c5baa
4 changed files with 26 additions and 26 deletions

View File

@ -16,7 +16,7 @@ int mouseDelay = 10;
// int keyboardDelay = 10;
// int CheckMouseButton(const char * const b,
// int CheckMouseButton(const char * const b,
// MMMouseButton * const button){
// if (!button) return -1;
@ -35,24 +35,24 @@ int mouseDelay = 10;
// return 0;
// }
int move_mouse(size_t x, size_t y){
MMPoint point;
int move_mouse(int32_t x, int32_t y){
MMSignedPoint point;
// int x = 103;
// int y = 104;
point = MMPointMake(x, y);
point = MMSignedPointMake(x, y);
moveMouse(point);
return 0;
}
int drag_mouse(size_t x, size_t y, MMMouseButton button){
int drag_mouse(int32_t x, int32_t y, MMMouseButton button){
// const size_t x = 10;
// const size_t y = 20;
// MMMouseButton button = LEFT_BUTTON;
MMPoint point;
point = MMPointMake(x, y);
MMSignedPoint point;
point = MMSignedPointMake(x, y);
dragMouse(point, button);
microsleep(mouseDelay);
@ -105,7 +105,7 @@ int mouse_toggle(char* d, MMMouseButton button){
toggleMouse(down, button);
microsleep(mouseDelay);
return 0;
}

View File

@ -65,20 +65,20 @@ typedef int MMMouseWheelDirection;
/* Immediately moves the mouse to the given point on-screen.
* It is up to the caller to ensure that this point is within the
* screen boundaries. */
void moveMouse(MMPoint point);
void moveMouse(MMSignedPoint point);
/* Like moveMouse, moves the mouse to the given point on-screen, but marks
* the event as the mouse being dragged on platforms where it is supported.
* It is up to the caller to ensure that this point is within the screen
* boundaries. */
void dragMouse(MMPoint point, const MMMouseButton button);
void dragMouse(MMSignedPoint point, const MMMouseButton button);
/* Smoothly moves the mouse from the current position to the given point.
* deadbeef_srand() should be called before using this function.
*
* Returns false if unsuccessful (i.e. a point was hit that is outside of the
* screen boundaries), or true if successful. */
bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed);
bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed);
// bool smoothlyMoveMouse(MMPoint point);
/* Returns the coordinates of the mouse on the current screen. */

View File

@ -66,7 +66,7 @@
* @param event The mouse move event (by ref).
* @param point The new mouse x and y.
*/
void calculateDeltas(CGEventRef *event, MMPoint point){
void calculateDeltas(CGEventRef *event, MMSignedPoint point){
/**
* The next few lines are a workaround for games not detecting mouse moves.
* See this issue for more information:
@ -91,10 +91,10 @@ void calculateDeltas(CGEventRef *event, MMPoint point){
* Move the mouse to a specific point.
* @param point The coordinates to move the mouse to (x, y).
*/
void moveMouse(MMPoint point){
void moveMouse(MMSignedPoint point){
#if defined(IS_MACOSX)
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
CGPointFromMMPoint(point),
CGPointFromMMSignedPoint(point),
kCGMouseButtonLeft);
calculateDeltas(&move, point);
@ -108,7 +108,7 @@ void moveMouse(MMPoint point){
XSync(display, false);
#elif defined(IS_WINDOWS)
// Mouse motion is now done using SendInput with MOUSEINPUT.
// Mouse motion is now done using SendInput with MOUSEINPUT.
// We use Absolute mouse positioning
#define MOUSE_COORD_TO_ABS(coord, width_or_height) ( \
((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1))
@ -129,7 +129,7 @@ void moveMouse(MMPoint point){
#endif
}
void dragMouse(MMPoint point, const MMMouseButton button){
void dragMouse(MMSignedPoint point, const MMMouseButton button){
#if defined(IS_MACOSX)
const CGEventType dragType = MMMouseDragToCGEventType(button);
CGEventRef drag = CGEventCreateMouseEvent(NULL, dragType,
@ -181,7 +181,7 @@ void toggleMouse(bool down, MMMouseButton button){
const CGEventType mouseType = MMMouseToCGEventType(down, button);
CGEventRef event = CGEventCreateMouseEvent(NULL,
mouseType, currentPos, (CGMouseButton)button);
CGEventPost(kCGSessionEventTap, event);
CFRelease(event);
#elif defined(USE_X11)
@ -192,7 +192,7 @@ void toggleMouse(bool down, MMMouseButton button){
// mouse_event(MMMouseToMEventF(down, button), 0, 0, 0, 0);
INPUT mouseInput;
mouseInput.type = INPUT_MOUSE;
mouseInput.mi.dx = 0;
mouseInput.mi.dy = 0;
@ -272,7 +272,7 @@ void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection){
/* Make scroll magnitude negative if we're scrolling down. */
cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection;
event = CGEventCreateScrollWheelEvent(NULL,
event = CGEventCreateScrollWheelEvent(NULL,
kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0);
CGEventPost(kCGHIDEventTap, event);
@ -408,10 +408,10 @@ bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed){
double velo_x = 0.0, velo_y = 0.0;
double distance;
while ((distance =
while ((distance =
crude_hypot((double)pos.x - endPoint.x, (double)pos.y - endPoint.y)
) > 1.0) {
double gravity = DEADBEEF_UNIFORM(5.0, 500.0);
// double gravity = DEADBEEF_UNIFORM(lowSpeed, highSpeed);
double veloDistance;
@ -432,7 +432,7 @@ bool smoothlyMoveMouse(MMPoint endPoint, double lowSpeed, double highSpeed){
return false;
}
moveMouse(pos);
moveMouse(MMSignedPointMake((int32_t)pos.x, (int32_t)pos.y));
/* Wait 1 - 3 milliseconds. */
microsleep(DEADBEEF_UNIFORM(lowSpeed, highSpeed));

View File

@ -359,8 +359,8 @@ func MoveMouse(x, y int) {
// Move move the mouse
func Move(x, y int) {
cx := C.size_t(x)
cy := C.size_t(y)
cx := C.int32_t(x)
cy := C.int32_t(y)
C.move_mouse(cx, cy)
}
@ -373,8 +373,8 @@ func DragMouse(x, y int, args ...string) {
func Drag(x, y int, args ...string) {
var button C.MMMouseButton = C.LEFT_BUTTON
cx := C.size_t(x)
cy := C.size_t(y)
cx := C.int32_t(x)
cy := C.int32_t(y)
if len(args) > 0 {
button = CheckMouse(args[0])