robotgo/mouse/goMouse.h

145 lines
2.9 KiB
C
Raw Permalink Normal View History

2016-11-10 06:34:13 +00:00
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
2016-12-10 18:41:08 +00:00
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
2016-11-10 06:34:13 +00:00
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
2016-10-06 10:41:37 +00:00
#include "../base/types.h"
2016-11-12 13:14:44 +00:00
#include "mouse_c.h"
2016-10-06 10:41:37 +00:00
2017-11-23 15:44:41 +00:00
// Global delays.
2020-03-05 19:28:28 +00:00
int mouseDelay = 0;
2016-10-06 10:41:37 +00:00
// int keyboardDelay = 10;
// int CheckMouseButton(const char * const b,
2018-12-27 16:44:38 +00:00
// MMMouseButton * const button){
2016-10-06 10:41:37 +00:00
// if (!button) return -1;
// if (strcmp(b, "left") == 0) {
2016-10-06 10:41:37 +00:00
// *button = LEFT_BUTTON;
// }
// else if (strcmp(b, "right") == 0) {
2016-10-06 10:41:37 +00:00
// *button = RIGHT_BUTTON;
// }
// else if (strcmp(b, "middle") == 0) {
2016-10-06 10:41:37 +00:00
// *button = CENTER_BUTTON;
// } else {
2016-10-06 10:41:37 +00:00
// return -2;
// }
// return 0;
// }
int move_mouse(int32_t x, int32_t y){
2019-12-01 12:46:04 +00:00
MMPointInt32 point;
2018-12-27 16:44:38 +00:00
// int x = 103;
// int y = 104;
2019-12-01 12:46:04 +00:00
point = MMPointInt32Make(x, y);
2016-10-06 10:41:37 +00:00
moveMouse(point);
return 0;
}
2018-12-27 16:44:38 +00:00
int drag_mouse(int32_t x, int32_t y, MMMouseButton button){
2017-05-09 13:56:22 +00:00
// const size_t x = 10;
// const size_t y = 20;
2018-12-27 16:44:38 +00:00
// MMMouseButton button = LEFT_BUTTON;
2016-10-06 10:41:37 +00:00
2019-12-01 12:46:04 +00:00
MMPointInt32 point;
point = MMPointInt32Make(x, y);
2016-10-06 10:41:37 +00:00
dragMouse(point, button);
microsleep(mouseDelay);
2017-11-23 15:44:41 +00:00
// printf("%s\n", "gyp-----");
2016-10-06 10:41:37 +00:00
return 0;
}
bool move_mouse_smooth(int32_t x, int32_t y, double lowSpeed,
double highSpeed, int msDelay){
MMPointInt32 point;
point = MMPointInt32Make(x, y);
2018-02-06 13:32:39 +00:00
bool cbool = smoothlyMoveMouse(point, lowSpeed, highSpeed);
microsleep(msDelay);
2016-10-06 10:41:37 +00:00
2018-02-06 13:32:39 +00:00
return cbool;
2016-10-06 10:41:37 +00:00
}
MMPointInt32 get_mouse_pos(){
MMPointInt32 pos = getMousePos();
2016-10-06 10:41:37 +00:00
2017-11-23 15:44:41 +00:00
// Return object with .x and .y.
2016-10-06 10:41:37 +00:00
// printf("%zu\n%zu\n", pos.x, pos.y );
return pos;
}
int mouse_click(MMMouseButton button, bool doubleC){
2016-11-12 07:17:52 +00:00
// MMMouseButton button = LEFT_BUTTON;
// bool doubleC = false;
if (!doubleC) {
2016-10-06 10:41:37 +00:00
clickMouse(button);
} else {
2016-10-06 10:41:37 +00:00
doubleClick(button);
}
microsleep(mouseDelay);
return 0;
}
int mouse_toggle(char* d, MMMouseButton button){
2016-10-24 05:41:41 +00:00
// MMMouseButton button = LEFT_BUTTON;
2016-10-06 10:41:37 +00:00
bool down = false;
if (strcmp(d, "down") == 0) {
2016-10-24 05:41:41 +00:00
down = true;
} else if (strcmp(d, "up") == 0) {
2016-10-24 05:41:41 +00:00
down = false;
} else {
2016-10-24 05:41:41 +00:00
return 1;
}
2016-10-06 10:41:37 +00:00
2016-10-24 05:41:41 +00:00
toggleMouse(down, button);
microsleep(mouseDelay);
2016-10-06 10:41:37 +00:00
return 0;
}
2017-12-29 12:24:47 +00:00
int set_mouse_delay(size_t val){
2017-11-23 15:44:41 +00:00
// int val = 10;
2016-10-06 10:41:37 +00:00
mouseDelay = val;
return 0;
}
2018-02-25 07:22:52 +00:00
int scroll(int x, int y, int msDelay){
scrollMouseXY(x, y);
microsleep(msDelay);
return 0;
}
int scroll_mouse(size_t scrollMagnitude, char *s){
2016-10-06 10:41:37 +00:00
// int scrollMagnitude = 20;
MMMouseWheelDirection scrollDirection;
if (strcmp(s, "up") == 0) {
2016-10-06 10:41:37 +00:00
scrollDirection = DIRECTION_UP;
} else if (strcmp(s, "down") == 0) {
2018-07-07 15:01:55 +00:00
scrollDirection = DIRECTION_DOWN;
} else {
2016-10-06 10:41:37 +00:00
// return "Invalid scroll direction specified.";
return 1;
}
scrollMouse(scrollMagnitude, scrollDirection);
microsleep(mouseDelay);
return 0;
}