Compare commits

..

1 Commits

Author SHA1 Message Date
coolneng cf8c2ab200 Simplify random coordinate setting 2020-07-28 15:31:55 +02:00
15 changed files with 19 additions and 69 deletions
Generated
-41
View File
@@ -1,41 +0,0 @@
{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1653893745,
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1654845941,
"narHash": "sha256-uXulXu4BQ9ch1ItV0FlL2Ns8X83m6unT5h/0X//VRLQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "7b3e907a6fef935794b5049c2c57c519853deb90",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}
-14
View File
@@ -1,14 +0,0 @@
{
description = "";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
devShell = import ./shell.nix { inherit pkgs; };
}
);
}
+4
View File
@@ -166,6 +166,10 @@ def on_button(callback, args=(), buttons=(LEFT, MIDDLE, RIGHT, X, X2), types=(UP
callback(*args) callback(*args)
_listener.add_handler(handler) _listener.add_handler(handler)
return handler return handler
def on_pressed(callback, args=()):
""" Invokes `callback` with `args` when the left button is pressed. """
return on_button(callback, args, [LEFT], [DOWN])
def on_click(callback, args=()): def on_click(callback, args=()):
""" Invokes `callback` with `args` when the left button is clicked. """ """ Invokes `callback` with `args` when the left button is clicked. """
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+8 -2
View File
@@ -20,6 +20,8 @@ EV_REL = 0x02
EV_ABS = 0x03 EV_ABS = 0x03
EV_MSC = 0x04 EV_MSC = 0x04
INVALID_ARGUMENT_ERRNO = 22
def make_uinput(): def make_uinput():
import fcntl, struct import fcntl, struct
@@ -29,8 +31,12 @@ def make_uinput():
fcntl.ioctl(uinput, UI_SET_EVBIT, EV_KEY) fcntl.ioctl(uinput, UI_SET_EVBIT, EV_KEY)
UI_SET_KEYBIT = 0x40045565 UI_SET_KEYBIT = 0x40045565
for i in range(256): try:
fcntl.ioctl(uinput, UI_SET_KEYBIT, i) for i in range(0x300):
fcntl.ioctl(uinput, UI_SET_KEYBIT, i)
except OSError as e:
if e.errno != INVALID_ARGUMENT_ERRNO:
raise e
BUS_USB = 0x03 BUS_USB = 0x03
uinput_user_dev = "80sHHHHi64i64i64i64i" uinput_user_dev = "80sHHHHi64i64i64i64i"
Binary file not shown.
Binary file not shown.
+7 -12
View File
@@ -1,25 +1,20 @@
from mouse import move from mouse import get_position, move
from secrets import randbelow from secrets import randbelow
from time import sleep from time import sleep
def erratic_movement(screen_width=800, screen_height=600): def erratic_movement(screen_width, screen_height):
"""
Moves the cursor to a random position with the screen's width and height as an upper bound
"""
move( move(
randbelow(screen_width), randbelow(screen_width), randbelow(screen_height),
randbelow(screen_height),
) )
def main(): def main():
""" screen_width = 800
Calls the movement function in an infinite loop, with a random delay between each call screen_height = 600
"""
while True: while True:
erratic_movement() erratic_movement(screen_width, screen_height, reset)
sleep(randbelow(90)) sleep(randbelow(10))
if __name__ == "__main__": if __name__ == "__main__":