作为exe运行时,如何打开和关闭此脚本?

时间:2018-07-11 16:31:12

标签: python

这是脚本:

from pynput.keyboard import Key, Controller
import time
import win32api

keyboard = Controller()
toggle = 1

state_left = win32api.GetKeyState(0x01)  
while True:
    a = win32api.GetKeyState(0x01)
    if a != state_left:  
        state_left = a
        if a < 0:
            if toggle == 1:
                keyboard.press('3')
                keyboard.release('3')

            if toggle == 2:
                keyboard.press('4')
                keyboard.release('4')

        else:
            if toggle == 1:
                toggle = 2
            else:
                toggle == 2
                toggle = 1

    time.sleep(0.05)

我的目标是能够在后台作为exe运行时打开和关闭此脚本(最好使用功能键)。我将如何去做?

0 个答案:

没有答案