python按y继续按其他键结束_按退出键退出循环

我不清楚你想用代码中的两个while True:循环来完成什么,所以我删除了其中一个循环,认为这可能是你想要的:import msvcrt

import win32api

import win32con

import time

def readch():

""" Get a single character on Windows.

see https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getch-getwch?view=vs-2019

"""

ch = msvcrt.getch()

if ch in b'\x00\xe0': # Arrow or function key prefix?

ch = msvcrt.getch() # Second call returns the actual key code.

return ch

def clickerleft(x, y):

""" Clicks on given x, y position.

Input:

x -- Horizontal position in pixels, starts from top-left position

y -- Vertical position in pixels, start from top-left position

"""

win32api.SetCursorPos((x, y))

win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)

win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)

print('Press Esc to quit or "a" to simulate mouse click')

while True:

if msvcrt.kbhit():

key = ord(readch())

if key == 97: # ord('a')

clickerleft(1193,757)

elif key == 27: # Escape key?

break

time.sleep(0.1)

print('Done')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值