def run_from_keys(self): self.mouse = mController() self.keyboard = kController() self.actControl = ActControl(self.content, keyboard=self.keyboard, mouse=self.mouse) self.actControl.start() with Listener(on_press=self.on_press) as self.listener: self.listener.join()
def click_send(msg): """模拟鼠标点击""" mouse = mController() keyboard = kController() mouse.press(Button.left) mouse.release(Button.left) keyboard.type(msg) # 聊天窗口在英文状态下输出文字 # 发送消息的快捷键是 Alt+s with keyboard.pressed(Key.alt): keyboard.press('s') keyboard.release('s')
def run(self): self.mouse = mController() self.keyboard = kController() self.actControl = ActControl(self.content, keyboard=self.keyboard, mouse=self.mouse) self.actControl.start() if self.actControl.running: self.actControl.stop_action() else: self.actControl.start_action()
def __init__(self): self.keyboard = kController() self.mouse = mController() self.instructions = LinkedList() self.special_keys = { 'space': Key.space, 'enter': Key.enter, 'lalt': Key.alt_l, 'lshift': Key.shift_l, 'right': Key.right, 'left': Key.left, 'down': Key.down, 'up': Key.up, 'esc': Key.esc, 'delete': Key.delete, 'backspace': Key.backspace, 'tab': Key.tab, 'capslock': Key.caps_lock, 'rshift': Key.shift_r, 'rctrl': Key.ctrl_r, 'ralt': Key.alt_r, 'f1': Key.f1, 'f2': Key.f2, 'f3': Key.f3, 'f4': Key.f4, 'f5': Key.f5, 'f6': Key.f6, 'f7': Key.f7, 'f8': Key.f8, 'f9': Key.f9, 'f10': Key.f10, 'f11': Key.f11, 'f12': Key.f12, 'leftClick': Button.left, 'rightClick': Button.right }
# coding:utf-8 import pyperclip import time import win32con import win32api from pynput.mouse import Button from pynput.mouse import Controller as mController from pynput.keyboard import Key from pynput.keyboard import Controller as kController mouse = mController() keyboard = kController() def stkinput(stk_id): mouse.position = (520, 150) mouse.click(button=Button.left) for num in range(6): win32api.keybd_event(int(stk_id[num]) + 48, 0, 0, 0) win32api.keybd_event( int(stk_id[num]) + 48, 0, win32con.KEYEVENTF_KEYUP, 0) # time.sleep(0.05) win32api.keybd_event(13, 0, 0, 0) win32api.keybd_event(13, 0, win32con.KEYEVENTF_KEYUP, 0) time.sleep(0.05) print('stk_ID input ') def copy_paste(flag): keyboard.press(Key.ctrl) time.sleep(0.1)
class TZController: __ms = mController() __kb = kController() _origin_pos = None def __init__(self): return ''' Some basic functions ''' def __time_break(self): time.sleep(0.1) def _click(self, pos): self.__ms.position = pos.value self.__ms.click(Button.left) self.__time_break() def _dbl_clk(self, pos): self.__ms.position = pos.value self.__ms.click(Button.left, 2) self.__time_break() def _r_click(self, pos): self.__ms.position = pos.value self.__ms.click(Button.right) self.__time_break() def _typein(self, text): self.__kb.type(text) self.__time_break() self.__kb.press(Key.enter) self.__kb.release(Key.enter) self.__time_break() ''' Regular Order Actions ''' def ticker(self, symbol): ''' Change ticker for regular order & chartingd window ''' self._dbl_clk(MOUSE_POS.TITLE_TICKER) self._typein(symbol) def price(self, price): ''' Set order price ''' self._dbl_clk(MOUSE_POS.INPUT_PRICE) self._typein(str(price)) self._click(MOUSE_POS.TITLE_TICKER) def qty(self, qty): ''' Set order quantity ''' self._dbl_clk(MOUSE_POS.INPUT_QUANTITY) self._typein(str(qty)) self._click(MOUSE_POS.TITLE_TICKER) def lmt(self, qty, price): ''' Prepare lmt order with qty/price ''' self.qty(qty) self.price(price) def buy(self): ''' Click BUY button ''' self._click(MOUSE_POS.BTN_BUY) def sell(self): ''' Click SELL button ''' self._click(MOUSE_POS.BTN_SELL) def short(self): ''' Click SHORT button ''' self._click(MOUSE_POS.BTN_SHORT) def cover(self): ''' Click COVER button ''' self._click(MOUSE_POS.BTN_COVER) def cancel(self): ''' Click CANCEL button ''' elf.__ms.position = MOUSE_POS.BTN_CANCEL.value self.__ms.click(Button.left) ''' Conditional Order Actions ''' def cdt_ticker(self, symbol): ''' Change ticker in Condition order window Ensure condition order window opening ''' self._dbl_clk(MOUSE_POS.CDT_INPUT_TICKER) self._typein(symbol) def cdt_buy_then_sell(self, target, stop, price, qty): ''' Conditional order 1 ''' self._click(MOUSE_POS.CDT_1st_ACTION_SEL) self._click(MOUSE_POS.CDT_1st_ACTION_BUY) self._click(MOUSE_POS.CDT_1st_TYPE_SEL) self._click(MOUSE_POS.CDT_1st_TYPE_LIMIT) self._dbl_clk(MOUSE_POS.CDT_1st_INPUT_QTY) self._typein(str(qty)) self._dbl_clk(MOUSE_POS.CDT_1st_INPUT_PRICE) self._typein(str(price)) ''' Conditional order 2 ''' self._click(MOUSE_POS.CDT_2nd_ACTION_SEL) self._click(MOUSE_POS.CDT_2nd_ACTION_SELL) self._click(MOUSE_POS.CDT_2nd_TYPE_SEL) self._click(MOUSE_POS.CDT_2nd_TYPE_RANGE) self._dbl_clk(MOUSE_POS.CDT_2nd_INPUT_QTY) self._typein(str(qty)) self._dbl_clk(MOUSE_POS.CDT_2nd_INPUT_HIGH_PRICE) self._typein(str(target)) # higher price as target self._dbl_clk(MOUSE_POS.CDT_2nd_INPUT_LOW_PRICE) self._typein(str(stop)) # lower price as stop def cdt_short_then_cover(self, target, stop, price, qty): ''' Conditional order 1 ''' self._click(MOUSE_POS.CDT_1st_ACTION_SEL) self._click(MOUSE_POS.CDT_1st_ACTION_SHORT) self._click(MOUSE_POS.CDT_1st_TYPE_SEL) self._click(MOUSE_POS.CDT_1st_TYPE_LIMIT) self._dbl_clk(MOUSE_POS.CDT_1st_INPUT_QTY) self._typein(str(qty)) self._dbl_clk(MOUSE_POS.CDT_1st_INPUT_PRICE) self._typein(str(price)) ''' Conditional order 2 ''' self._click(MOUSE_POS.CDT_2nd_ACTION_SEL) self._click(MOUSE_POS.CDT_2nd_ACTION_COVER) self._click(MOUSE_POS.CDT_2nd_TYPE_SEL) self._click(MOUSE_POS.CDT_2nd_TYPE_RANGE) self._dbl_clk(MOUSE_POS.CDT_2nd_INPUT_QTY) self._typein(str(qty)) self._dbl_clk(MOUSE_POS.CDT_2nd_INPUT_HIGH_PRICE) self._typein(str(stop)) # higher price as stop self._dbl_clk(MOUSE_POS.CDT_2nd_INPUT_LOW_PRICE) self._typein(str(target)) # lower price as target def cdt_send(self): self._click(MOUSE_POS.CDT_BTN_SEND) def cdt_cancel(self): self._click(MOUSE_POS.CDT_BTN_CANCEL) ''' Get ''' def cur_pos(self): ''' Return current position size for current ticker ''' self._dbl_clk(MOUSE_POS.INPUT_QUANTITY) self._r_click(MOUSE_POS.INPUT_QUANTITY) self._click(MOUSE_POS.INPUT_QUANTITY_COPY) return clipboard.paste() def get_mouse_pos(self): ''' Put your mouse on certain input or button, Run this function to get its position, Copy & paste it to config ''' print('The current pointer position is {0}'.format( mController().position))
import numpy as np import time import cv2 from mss import mss import os from tkinter import Tk import tetris_logic import subprocess import argparse from pynput.keyboard import Key, Controller as kController keyboardCont = kController() parser = argparse.ArgumentParser(description="Optimize some constants.") # Arguments parser.add_argument("constant", choices=[ "hole_cost", "hole_height_cost", "height_cost", "jagged_cost", "line_value", "height_threshold" ]) parser.add_argument("--low", type=int, help="Lower bound of optimization", default=10) parser.add_argument("--high", type=int, help="Upper bound of optimization", default=10) parser.add_argument("--trials", type=int,