Skip to content

Instantly share code, notes, and snippets.

@enthus1ast
Created October 15, 2021 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enthus1ast/2f9c16de5814636e2fdd983902e1f262 to your computer and use it in GitHub Desktop.
Save enthus1ast/2f9c16de5814636e2fdd983902e1f262 to your computer and use it in GitHub Desktop.
{.link: "libuiohook.dll".}
type
log_level* = enum
LOG_LEVEL_DEBUG = 1, LOG_LEVEL_INFO, LOG_LEVEL_WARN, LOG_LEVEL_ERROR
logger_t* = proc (a1: cuint; a2: cstring, params: varargs[int]): bool {.varargs,cdecl.}
## Begin Virtual Event Types and Data Structures
type
INNER_C_UNION_out_69* {.bycopy.} = object {.union.}
keyboard*: keyboard_event_data
mouse*: mouse_event_data
wheel*: mouse_wheel_event_data
event_type* = enum
EVENT_HOOK_ENABLED = 1, EVENT_HOOK_DISABLED, EVENT_KEY_TYPED, EVENT_KEY_PRESSED,
EVENT_KEY_RELEASED, EVENT_MOUSE_CLICKED, EVENT_MOUSE_PRESSED,
EVENT_MOUSE_RELEASED, EVENT_MOUSE_MOVED, EVENT_MOUSE_DRAGGED, EVENT_MOUSE_WHEEL
screen_data* {.bycopy.} = object
number*: uint8
x*: uint16
y*: uint16
width*: uint16
height*: uint16
keyboard_event_data* {.bycopy.} = object
keycode*: uint16
rawcode*: uint16
keychar*: uint16
key_pressed_event_data* = keyboard_event_data
key_released_event_data* = keyboard_event_data
key_typed_event_data* = keyboard_event_data
mouse_event_data* {.bycopy.} = object
button*: uint16
clicks*: uint16
x*: uint16
y*: uint16
mouse_pressed_event_data* = mouse_event_data
mouse_released_event_data* = mouse_event_data
mouse_clicked_event_data* = mouse_event_data
mouse_wheel_event_data* {.bycopy.} = object
clicks*: uint16
x*: uint16
y*: uint16
`type`*: uint8
amount*: uint16
rotation*: uint16
direction*: uint8
uiohook_event* {.bycopy.} = object
`type`*: event_type
time*: uint64
mask*: uint16
reserved*: uint16
data*: INNER_C_UNION_out_69
dispatcher_t* = proc (a1: ptr uiohook_event) {.cdecl.}
## End Virtual Event Types and Data Structures
## Set the logger callback functions.
proc hook_set_logger_proc*(logger_proc: logger_t) {.importc, cdecl.}
## Send a virtual event back to the system.
proc hook_post_event*(event: ptr uiohook_event) {.importc, cdecl.}
## Set the event callback function.
proc hook_set_dispatch_proc*(dispatch_proc: dispatcher_t) {.importc, cdecl.}
## Insert the event hook.
proc hook_run*(): cint {.importc, cdecl.}
## Withdraw the event hook.
proc hook_stop*(): cint {.importc, cdecl.}
## Retrieves an array of screen data for each available monitor.
proc hook_create_screen_info*(count: ptr cuchar): ptr screen_data {.importc, cdecl.}
## Retrieves the keyboard auto repeat rate.
proc hook_get_auto_repeat_rate*(): clong {.importc, cdecl.}
## Retrieves the keyboard auto repeat delay.
proc hook_get_auto_repeat_delay*(): clong {.importc, cdecl.}
## Retrieves the mouse acceleration multiplier.
proc hook_get_pointer_acceleration_multiplier*(): clong {.importc, cdecl.}
## Retrieves the mouse acceleration threshold.
proc hook_get_pointer_acceleration_threshold*(): clong {.importc, cdecl.}
## Retrieves the mouse sensitivity.
proc hook_get_pointer_sensitivity*(): clong {.importc, cdecl.}
## Retrieves the double/triple click interval.
proc hook_get_multi_click_time*(): clong {.importc, cdecl.}
when isMainModule:
proc logger(a1: cuint; a2: cstring, params: varargs[int]): bool {.cdecl,varargs.} =
# todo, how to get vararg params correctly?
# echo $a1, "->", a2
# echo params
discard
proc dispatcher(a1: ptr uiohook_event) {.cdecl.} =
echo a1[]
hook_set_logger_proc(logger)
hook_set_dispatch_proc(dispatcher)
echo hook_run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment