Python按键脚本

Python按键脚本

from pynput.mouse import Button, Controller
import time

# 获取鼠标对象
mouse = Controller()

# 输出鼠标当前的坐标
print(mouse.position)

# 将新的坐标赋值给鼠标对象
mouse.position = (100, 500)

for index in range(0, 30):
    # 鼠标移动到指定坐标轴
    mouse.move(index, -index)
    print(mouse.position)
    time.sleep(0.01)

for index in range(0, 30):
    # 鼠标移动到指定坐标轴
    mouse.move(-index, index)
    print(mouse.position)
    time.sleep(0.01)

# 鼠标右键按下
mouse.press(Button.right)

time.sleep(0.01)

# 鼠标右键抬起
mouse.release(Button.right)

# 鼠标左键点击
mouse.click(Button.left, 1)

# 鼠标滚轮滚动距离500
mouse.scroll(0, 500)

from pynput.keyboard import Key, Controller, KeyCode

# 键盘控制对象
keyboard = Controller()

# 按下 a 键
keyboard.press('a')
# 释放 a 键
keyboard.release('a')

# 按下 Shift 键
keyboard.press(Key.shift)
keyboard.press('b')
keyboard.release('b')
keyboard.press('c')
keyboard.release('c')
# 释放 Shift 键
keyboard.release(Key.esc)

# 按下 Shift 键,然后依次按下其他按键,完成后Shift键自动释放
with keyboard.pressed(Key.shift):
    keyboard.press('d')
    keyboard.release('d')
    keyboard.press('e')
    keyboard.release('e')

# 依次按下 python (包括前面的空格)
keyboard.type(' python')

# 按下 vk值为56的键 shift 键
keyboard.touch(KeyCode.from_vk(56), True)
keyboard.touch('a', True)
keyboard.touch('a', False)
# 释放 shift 键
keyboard.touch(Key.shift, False)
from pynput.keyboard import Key, Controller
import threading
from pynput import mouse
import tkinter
from sys import exit

# 实例键盘组件
keyboard = Controller()


class MouseActionListener(threading.Thread):

    def __init__(self):
        super().__init__()

    def run(self):
        # 鼠标点击事件
        def on_click(x, y, button, pressed):
            print(button)
            if str(button) == 'Button.left':
                # 按下 ctrl 键,然后依次按下其他按键,完成后ctrl键自动释放
                with keyboard.pressed(Key.ctrl):
                    keyboard.press(Key.alt)
                    keyboard.press('.')
                    keyboard.release(Key.alt)
                    keyboard.release('.')
            elif str(button) == 'Button.middle':
                with keyboard.pressed(Key.ctrl):
                    keyboard.press(Key.alt)
                    keyboard.press(',')
                    keyboard.release(Key.alt)
                    keyboard.release(',')

        with mouse.Listener(on_click=on_click) as listener:
            listener.join()

    @classmethod
    def stop(cls):
        exit()


def button_onClick(action):
    m1 = MouseActionListener()

    if action == 'listener':
        if startListenerBtn['text'] == '开启':
            m1.daemon = True
            m1.start()
            startListenerBtn['text'] = '开启中...再次点击停止进程'

        elif startListenerBtn['text'] == '开启中...再次点击停止进程':
            m1.stop()
            startListenerBtn['text'] = '开启'


if __name__ == '__main__':
    root = tkinter.Tk()
    root.title('翻页神器')
    root.geometry('250x100')

    startListenerBtn = tkinter.Button(root, text="开启", command=lambda: button_onClick('listener'))
    startListenerBtn.place(x=35, y=10, width=180, height=80)

    root.mainloop()

#include<stdio.h> 
main() { 
  int a=010,b=10; 
  printf("%d,%d\n",a++,--b);
}
上一篇:javascript – 鼠标右键单击Firefox触发点击事件


下一篇:Unity InputSystem