简体   繁体   English

Python 密钥。 钥匙

[英]Python Key. keys

Hey I'm making an autoclicker with pyautogui and I don't know the keys I can put in for the Key.嘿,我正在用 pyautogui 制作一个自动点击器,但我不知道我可以为 Key 输入的密钥。 (variables at the beginning) I want to put in left mouse button down. (变量开头)我想把鼠标左键按下。 If I just put a key it gives me an error so yeah I can't find this anywhere.如果我只是放一个键,它会给我一个错误,所以是的,我在任何地方都找不到这个。

import pyautogui
from pynput.keyboard import *
from pynput import mouse
import random
#  ======== settings ========

delay = random.uniform(.03,.22)  # in seconds
resumeKey = Key.f4
pauseKey = Key.f6
exitKey = Key.esc


pause = True
running = True

def on_press(key):
    global running, pause

    if key == resumeKey:
        pause = False
        print("[Resumed]")
    elif key == pauseKey:
        pause = True
        print("[Paused]")
    elif key == exitKey:
        running = False
        print("[Exit]")
mouseLis = mouse.Listener(on_click = on_click)
mouseLis.start()
def on_click(x,y,button,pressed):
    if button == mouse.Button.left:
        pause = False


def main():
    lis = Listener(on_press=on_press)
    lis.start()

    while running:
        if not pause:
            delay = random.uniform(.03,.22)
            pyautogui.click(pyautogui.position())
            pyautogui.PAUSE = delay
    lis.stop()
mouseLis.stop()

if __name__ == "__main__":
    main()

The mouse needs its own listener, it doesn't have a keybinding for the keyboard as far as I can tell.鼠标需要自己的监听器,据我所知,它没有键盘的键绑定。 Something like this: (Found in the documentation here .)像这样:(在此处的文档中找到。)

from pynput import mouse

def on_click(x, y, button, pressed):
    # do something here

mouse_lis = mouse.Listener(on_click=on_click)
mouse_lis.start()

To solve this I just created another function called on_click that handled the mouse button presses.为了解决这个问题,我刚刚创建了另一个名为on_click的 function 来处理鼠标按钮按下。

This function was这个 function 是

def on_click(x,y,button,pressed):
    if button == mouse.Button.left:
        print("Output")

Basically it takes the click and if the button clicked was the left mouse button then it prints the output in the if statement.基本上它需要单击,如果单击的按钮是鼠标左键,那么它会在 if 语句中打印 output。 There are also three other parameters you have to mess around with if you would like.如果您愿意,还必须处理其他三个参数。

In your main function add在你的主要 function 添加

mouseLis = mouse.Listener(on_click = on_click)
mouseLis.start()

This creates the actual mouse listener that will then work to listen to the mouse clicks.这将创建实际的鼠标侦听器,然后该侦听器将用于侦听鼠标点击。

At the end of your main function, be sure to include在你的主要 function 的末尾,一定要包括

mouseLis.stop()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python字典-将数组附加到特定键的字典中。 - Python dictionaries - appending arrays to a dictionary for a specific key. 遍历python字典并用key编辑所有字符串。 - Iterate through python dictionary and edit all strings with key. 返回密钥:子密钥对按密钥的子密钥的子密钥排序。 蟒蛇 - getting back key:subkey pair sorted on subkey of subkey of key. python python:如果密钥不在字典中,则添加密钥。 防止多线程竞争 - python: if key not in dictionary add the key. preventing race conditions with multiple threads RSA Python和扩展欧几里得算法来生成私钥。 变量为无 - RSA Python & Extended Euclidean algorithm to generate the private key. Variable is None Python字典:“键”中所有“不同的第一个单词”的所有值的总和。 - Python dictionary: Sum of all the values for all the “distinct first word” in the “key.” PYTHON 3(1)字典Python大写值存在于单个键中。 (2)为什么python中的数据类型集不返回True元素? - PYTHON 3 (1) Dictionary Python upper case values present in a single key. (2) Why datatype sets in python does not return True element? OrderedDict:无法使用键返回d的项目。 引发KeyError - OrderedDict: Unable Return the item of d with key key. Raises a KeyError 按键排序字典列表。 如果 key 缺失,假设一个连续的编号 - Sort a list of dict by key. If key is missing, assume a consecutive numbering python KeyError 如果密钥不在 b.keys() 中 - python KeyError if key not in b.keys()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM