Skip to content

Commit

Permalink
upgrade to 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
taojy123 committed Oct 19, 2020
1 parent fce7d70 commit 7d46502
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 16 deletions.
24 changes: 17 additions & 7 deletions Frame1.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import ctypes


VERSION = '3.1'


MOUSE_MOVE_INTERVAL_MS = 200 # 录制鼠标轨迹的精度,数值越小越精准,但同时可能产生大量的冗余

wx.NO_3D = 0
Expand Down Expand Up @@ -66,7 +69,7 @@ def _init_ctrls(self, prnt):
wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
pos=wx.Point(506, 283), size=wx.Size(366, 201),
style=wx.STAY_ON_TOP | wx.DEFAULT_FRAME_STYLE,
title='Keymouse Go')
title='KeymouseGo v%s' % VERSION)
self.SetClientSize(wx.Size(350, 205))

self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
Expand Down Expand Up @@ -483,12 +486,19 @@ def run_script_once(cls, script_path, thd=None):
if event_type == 'EM':
x, y = action

# ctypes.windll.user32.SetCursorPos(x, y)
# win32api.SetCursorPos([x, y])
if action == [-1, -1]:
# 约定 [-1, -1] 表示鼠标保持原位置不动
pass
else:
# 挪动鼠标 普通做法
# ctypes.windll.user32.SetCursorPos(x, y)
# or
# win32api.SetCursorPos([x, y])

nx = int(x * 65535 / sw)
ny = int(y * 65535 / sh)
win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE|win32con.MOUSEEVENTF_MOVE, nx, ny, 0, 0)
# 更好的兼容 win10 屏幕缩放问题
nx = int(x * 65535 / sw)
ny = int(y * 65535 / sh)
win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE|win32con.MOUSEEVENTF_MOVE, nx, ny, 0, 0)

if message == 'mouse left down':
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Expand Down Expand Up @@ -555,7 +565,7 @@ def OnTaskBarLeftDClick(self, event):
self.frame.Raise()

def OnAbout(self, event):
wx.MessageBox('https://github.com/taojy123/KeymouseGo', 'KeymouseGo v3.0')
wx.MessageBox('https://github.com/taojy123/KeymouseGo', 'KeymouseGo v%s' % VERSION)
event.Skip()

def OnCloseshow(self, event):
Expand Down
50 changes: 42 additions & 8 deletions KeymouseGo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#!/usr/bin/env python
#Boa:App:BoaApp

import Frame1
import wx
import time
import os
import sys
import json
import threading

import wx
import pyWinhook
import pythoncom

import Frame1


modules = {'Frame1': [1, 'Main frame of Application', u'Frame1.py']}
Expand All @@ -24,13 +30,41 @@ def main():
application.MainLoop()



def single_run(script_path, run_times=1):
j = 0
while j < run_times or run_times == 0:
j += 1
print('===========', j, '==============')
Frame1.RunScriptClass.run_script_once(script_path)
print('script run finish!')

t = HookThread()
t.start()

try:
j = 0
while j < run_times or run_times == 0:
j += 1
print('===========', j, '==============')
Frame1.RunScriptClass.run_script_once(script_path)
print('script run finish!')
except Exception as e:
raise e
finally:
os._exit(0)


class HookThread(threading.Thread):

def run(self):

def on_keyboard_event(event):
key_name = event.Key.lower()
stop_name = 'f9'
if key_name == stop_name:
print('break exit!')
os._exit(0)
return True

hm = pyWinhook.HookManager()
hm.KeyAll = on_keyboard_event
hm.HookKeyboard()
pythoncom.PumpMessages()


if __name__ == '__main__':
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# KeymouseGo v3.0
# KeymouseGo v3.1

功能:记录用户的鼠标键盘操作,通过触发按钮自动执行之前记录的操作,可设定执行的次数,可以理解为 `精简绿色版``按键精灵`

Expand Down Expand Up @@ -132,6 +132,14 @@
暂时没法打包 `x86` 版本,32 位系统的同学请自行源码编译,或 [下载v1.5老版本](https://github.com/taojy123/KeymouseGo/releases/tag/v1.5) 使用


## v3.1

针对这个 issue(https://github.com/taojy123/KeymouseGo/issues/39) 增加了两个功能点

+ 命令行启动模式中可以随时按下 `F9` 热键,来终止脚本运行
+ 模拟鼠标点击的脚本语句中可以设定坐标点为 `[-1, -1]`, 用以表示在鼠标当前位置直接点击


## v3.0

因为兼容 macOS 遇到的很大的阻碍,最终放弃跨平台,血泪史可参看这两个 issue:
Expand Down

0 comments on commit 7d46502

Please sign in to comment.