Created
October 18, 2010 08:45
-
-
Save mizchi/631927 to your computer and use it in GitHub Desktop.
mouse operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| #-*- encoding:utf-8 -*- | |
| """ | |
| OSXのマウスイベントを操作するスクリプトのサンプル | |
| require : PyObjC | |
| v{CGPoint=dd}は環境によってddだったりffだったりした | |
| """ | |
| import objc | |
| from AppKit import NSScreen | |
| from time import sleep | |
| def clickMouse(x, y, button): # 1が左,2が右,3がホイールボタン | |
| bndl = objc.loadBundle('CoreGraphics', globals(), '/System/Library/Frameworks/ApplicationServices.framework') | |
| objc.loadBundleFunctions(bndl, globals(), [('CGPostMouseEvent', 'v{CGPoint=dd}III')]) | |
| CGPostMouseEvent((x, y), 1, button, 1) | |
| CGPostMouseEvent((x, y), 1, button, 0) | |
| def moveMouse(x, y): | |
| bndl = objc.loadBundle('CoreGraphics', globals(), '/System/Library/Frameworks/ApplicationServices.framework') | |
| objc.loadBundleFunctions(bndl, globals(), [('CGWarpMouseCursorPosition', 'v{CGPoint=dd}')]) | |
| CGWarpMouseCursorPosition((x, y)) | |
| if __name__ == "__main__": | |
| cnt = 0 | |
| for i in range(3): | |
| moveMouse( 100+i*10, 100) | |
| sleep(1) | |
| clickMouse(10, 10, 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is because you use python 3. Write instead
objc.loadBundleFunctions(bndl,` globals(), [('CGPostMouseEvent', b'v{CGPoint=dd}III')])