Repository navigation
Expand file tree
/
Copy pathclicker.py
More file actions
68 lines (59 loc) · 1.99 KB
/
Copy pathclicker.py
File metadata and controls
68 lines (59 loc) · 1.99 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
# -*- coding: utf-8 -*-
from Quartz.CoreGraphics import *
from time import sleep
from AppKit import NSApplication, NSApp
from Foundation import NSObject, NSLog
from Cocoa import NSEvent, NSKeyDownMask
from PyObjCTools import AppHelper
import _thread
import random
flag = False
# Keyboard Events
class AppDelegate(NSObject):
def applicationDidFinishLaunching_(self, notification):
mask = NSKeyDownMask
NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(mask, handler)
# Where the magic begins
def handler(event):
global flag
try:
#NSLog(u"%@", event)
#print 'keycode: ' + str(event.keyCode())
if (int(event.keyCode()) == 6): # 6 - Z Key
flag = not(flag)
status = 'activated' if flag else 'deactivated'
print('clicker ' + status)
clicker()
elif (int(event.keyCode()) == 53): # 53 - ESC Key
AppHelper.stopEventLoop()
except KeyboardInterrupt:
AppHelper.stopEventLoop()
# Mouse Events
def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
result = CGEventPost(kCGHIDEventTap, theEvent)
return result
def mouseclick(posx,posy):
up = mouseEvent(kCGEventLeftMouseDown, posx,posy)
down = mouseEvent(kCGEventLeftMouseUp, posx,posy)
return str(up) + ' ' + str(down)
# the clicker
def clicker():
global flag
print('clicker started')
while(True):
if(flag):
ourEvent = CGEventCreate(None)
currentpos = CGEventGetLocation(ourEvent) # Save current mouse position
mouseclick(int(currentpos.x),int(currentpos.y))
sleep(0.01 * random.randint(1,5))
#main function
def main():
app = NSApplication.sharedApplication()
delegate = AppDelegate.alloc().init()
NSApp().setDelegate_(delegate)
AppHelper.runEventLoop()
if __name__ == '__main__':
_thread.start_new_thread(clicker,())
main()