Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何退出使用python脚本pyhook使用快捷键?_Python_Windows_Actionscript 3_Pyhook - Fatal编程技术网

如何退出使用python脚本pyhook使用快捷键?

如何退出使用python脚本pyhook使用快捷键?,python,windows,actionscript-3,pyhook,Python,Windows,Actionscript 3,Pyhook,这是我打算做的一个可以自动粘贴到聊天窗口并用鼠标点击发送的小脚本 但是,此脚本只能运行到运行后才能停止 我的问题是如何设置快捷键(如F12)您可以按F12停止脚本 脚本代码如下: # _*_ coding:UTF-8 _*_ import win32api import win32con import win32gui from ctypes import * import time import msvcrt import threading from time import sleep s

这是我打算做的一个可以自动粘贴到聊天窗口并用鼠标点击发送的小脚本

但是,此脚本只能运行到运行后才能停止

我的问题是如何设置快捷键(如F12)您可以按F12停止脚本

脚本代码如下:

# _*_ coding:UTF-8 _*_
import win32api
import win32con
import win32gui
from ctypes import *
import time
import msvcrt
import threading
from time import sleep

stop = 2
def mouse_click(x=None,y=None):
    if not x is None and not y is None:
        mouse_move(x,y)
        time.sleep(0.05)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)     
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)   
def mouse_move(x,y):
    windll.user32.SetCursorPos(x, y)

def baozou():
    global stop
for event in range(1,50):
    mouse_click(1150,665)
    win32api.keybd_event(17,0,0,0)  
    win32api.keybd_event(86,0,0,0)  
    win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0) 
    win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0) 
    mouse_click(1272,669)
    time.sleep(0.1)
    if stop == 1:
        sys.exit()

def Break():
    global stop
    if ord(msvcrt.getch()) == 123:
        stop = 1

if __name__ == "__main__":
    t = threading.Thread(target = baozou)
    f = threading.Thread(target = Break)
    t.start()
    f.start()

请帮我一把

我已经设法解决了这个问题,我的工作代码是:

# _*_ coding:UTF-8 _*_
import win32api
import win32con
import win32gui
from ctypes import *
import time
import msvcrt
import threading
from time import sleep
import sys
import ctypes.wintypes


EXIT = False
def mouse_click(x=None,y=None):
    if not x is None and not y is None:
        mouse_move(x,y)
        time.sleep(0.05)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)     
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)   
def mouse_move(x,y):
    windll.user32.SetCursorPos(x, y)

class Hotkey(threading.Thread):  #创建一个Thread.threading的扩展类  

    def run(self):  
        global EXIT  #定义全局变量,这个可以在不同线程见共用。  
        user32 = ctypes.windll.user32  #加载user32.dll  
        if not user32.RegisterHotKey(None, 99, win32con.MOD_ALT, win32con.VK_F3):   # 注册快捷键 alt + f3 并判断是否成功。  
            raise                                                                  # 返回一个错误信息  
    #以下为判断快捷键冲突,释放快捷键  
        try:  
            msg = ctypes.wintypes.MSG()  
            while user32.GetMessageA(ctypes.byref(msg), None, 0, 0) != 0:  
                if msg.message == win32con.WM_HOTKEY:  
                    if msg.wParam == 99:  
                        EXIT = True  
                        return  
                user32.TranslateMessage(ctypes.byref(msg))  
                user32.DispatchMessageA(ctypes.byref(msg))  
            finally:  
                user32.UnregisterHotKey(None, 1)  


if __name__ == "__main__":
    hotkey = Hotkey()  
    hotkey.start()  
    for event in range(1,30):
        mouse_click(1150,665)
        win32api.keybd_event(17,0,0,0)  
        win32api.keybd_event(86,0,0,0)  
        win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0) 
        win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0) 
        mouse_click(1272,669)
        if EXIT:
            sys.exit()

我已经设法解决了这个问题,我的工作代码是:

# _*_ coding:UTF-8 _*_
import win32api
import win32con
import win32gui
from ctypes import *
import time
import msvcrt
import threading
from time import sleep
import sys
import ctypes.wintypes


EXIT = False
def mouse_click(x=None,y=None):
    if not x is None and not y is None:
        mouse_move(x,y)
        time.sleep(0.05)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)     
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)   
def mouse_move(x,y):
    windll.user32.SetCursorPos(x, y)

class Hotkey(threading.Thread):  #创建一个Thread.threading的扩展类  

    def run(self):  
        global EXIT  #定义全局变量,这个可以在不同线程见共用。  
        user32 = ctypes.windll.user32  #加载user32.dll  
        if not user32.RegisterHotKey(None, 99, win32con.MOD_ALT, win32con.VK_F3):   # 注册快捷键 alt + f3 并判断是否成功。  
            raise                                                                  # 返回一个错误信息  
    #以下为判断快捷键冲突,释放快捷键  
        try:  
            msg = ctypes.wintypes.MSG()  
            while user32.GetMessageA(ctypes.byref(msg), None, 0, 0) != 0:  
                if msg.message == win32con.WM_HOTKEY:  
                    if msg.wParam == 99:  
                        EXIT = True  
                        return  
                user32.TranslateMessage(ctypes.byref(msg))  
                user32.DispatchMessageA(ctypes.byref(msg))  
            finally:  
                user32.UnregisterHotKey(None, 1)  


if __name__ == "__main__":
    hotkey = Hotkey()  
    hotkey.start()  
    for event in range(1,30):
        mouse_click(1150,665)
        win32api.keybd_event(17,0,0,0)  
        win32api.keybd_event(86,0,0,0)  
        win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0) 
        win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0) 
        mouse_click(1272,669)
        if EXIT:
            sys.exit()