-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcursor.m
34 lines (27 loc) · 824 Bytes
/
cursor.m
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
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
#import <lauxlib.h>
static int cursor_warpToPoint(lua_State* L){
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
NSPoint target = CGPointMake(roundf(x), roundf(y));
CGWarpMouseCursorPosition(target);
return 1;
}
static int cursor_position(lua_State* L){
NSPoint mouseLoc;
mouseLoc = [NSEvent mouseLocation];
lua_newtable(L);
lua_pushnumber(L, mouseLoc.x); lua_setfield(L, -2, "x");
lua_pushnumber(L, mouseLoc.y); lua_setfield(L, -2, "y");
return 1;
}
static const luaL_Reg cursorlib[] = {
{"warptopoint", cursor_warpToPoint},
{"position", cursor_position},
{} // necessary sentinel
};
int luaopen_mjolnir_jstevenson_cursor_internal(lua_State* L) {
luaL_newlib(L, cursorlib);
return 1;
}