/
input.go
54 lines (44 loc) · 1.45 KB
/
input.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
/*
#cgo LDFLAGS: -framework ApplicationServices -framework Foundation
#include <ApplicationServices/ApplicationServices.h>
#include <unistd.h>
#include <stdio.h>
CGPoint get_curr_pos();
void move_mouse(float x, float y) {
CGPoint current = get_curr_pos();
CGPoint move_to = CGPointMake(x, y);
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, move_to,
kCGMouseButtonLeft);
CGEventPost(kCGHIDEventTap, move);
CFRelease(move);
}
void mouse_click_down(uint32_t button) {
CGEventRef click = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown,
get_curr_pos(), button);
CGEventPost(kCGHIDEventTap, click);
CFRelease(click);
}
void mouse_click_up(uint32_t button) {
CGEventRef click = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseUp,
get_curr_pos(), button);
CGEventPost(kCGHIDEventTap, click);
CFRelease(click);
}
CGPoint get_curr_pos() {
CGEventRef ourEvent = CGEventCreate(NULL);
CGPoint point = CGEventGetLocation(ourEvent);
CFRelease(ourEvent);
return point;
}
*/
import "C"
func GetDisplayWidth() int {
return int(C.CGDisplayPixelsWide(C.CGMainDisplayID()));
}
func GetDisplayHeight() int {
return int(C.CGDisplayPixelsHigh(C.CGMainDisplayID()));
}
func MoveMouse(movement Movement) {
C.move_mouse(C.float(movement.x), C.float(movement.y))
}