forked from DorskFR/LeaguePyBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,34 @@ | ||
from time import sleep | ||
import os | ||
from .keyboard_pynput import KeyboardPynput | ||
from .keyboard_pydirectinput import KeyboardPyDirectInput | ||
|
||
from pynput.keyboard import Controller, Key | ||
|
||
|
||
class Keyboard: | ||
def __init__(self, sleep=0): | ||
self.keyboard = Controller() | ||
self.sleep = sleep | ||
|
||
def press(self, key): | ||
sleep(self.sleep) | ||
self.keyboard.press(key) | ||
|
||
def release(self, key): | ||
sleep(self.sleep) | ||
self.keyboard.release(key) | ||
if os.name == "nt": | ||
self.keyboard = KeyboardPyDirectInput() | ||
else: | ||
self.keyboard = KeyboardPynput() | ||
self.sleep=sleep | ||
|
||
def input_key(self, key): | ||
sleep(self.sleep) | ||
if "Shift" in key: | ||
with self.keyboard.pressed(Key.shift): | ||
self.keyboard.tap(key.replace("Shift", "")) | ||
elif "Ctrl" in key: | ||
with self.keyboard.pressed(Key.ctrl): | ||
self.keyboard.tap(key.replace("Ctrl", "")) | ||
elif "Alt" in key: | ||
with self.keyboard.pressed(Key.alt): | ||
self.keyboard.tap(key.replace("Alt", "")) | ||
else: | ||
self.keyboard.tap(key) | ||
self.keyboard.input_key(key) | ||
|
||
def input_word(self, word: str): | ||
sleep(self.sleep) | ||
self.keyboard.type(word) | ||
self.keyboard.input_word(word) | ||
|
||
def esc(self): | ||
sleep(self.sleep) | ||
self.keyboard.tap(Key.esc) | ||
self.keyboard.esc() | ||
|
||
def enter(self): | ||
sleep(self.sleep) | ||
self.keyboard.tap(Key.enter) | ||
self.keyboard.enter() | ||
|
||
def space(self): | ||
sleep(self.sleep) | ||
self.keyboard.tap(Key.space) | ||
self.keyboard.space() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pydirectinput | ||
|
||
pydirectinput.FAILSAFE = False | ||
|
||
class KeyboardPyDirectInput: | ||
def __init__(self): | ||
pass | ||
|
||
def input_key(self, key: str): | ||
if "Shift" in key: | ||
pydirectinput.keyDown("shift") | ||
pydirectinput.press(key.replace("Shift", "")) | ||
pydirectinput.keyUp("shift") | ||
elif "Ctrl" in key: | ||
pydirectinput.keyDown("ctrl") | ||
pydirectinput.press(key.replace("Ctrl", "")) | ||
pydirectinput.keyUp("ctrl") | ||
elif "Alt" in key: | ||
pydirectinput.keyDown("alt") | ||
pydirectinput.press(key.replace("Alt", "")) | ||
pydirectinput.keyUp("alt") | ||
else: | ||
pydirectinput.press(key) | ||
|
||
def input_word(self, word: str): | ||
for letter in word: | ||
self.keyboard.input_key(letter) | ||
|
||
def esc(self): | ||
pydirectinput.press("esc") | ||
|
||
def enter(self): | ||
pydirectinput.press("enter") | ||
|
||
def space(self): | ||
pydirectinput.press("space") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from pynput.keyboard import Controller, Key | ||
|
||
class KeyboardPynput: | ||
def __init__(self): | ||
self.keyboard = Controller() | ||
|
||
def input_key(self, key): | ||
if "Shift" in key: | ||
with self.keyboard.pressed(Key.shift): | ||
self.keyboard.tap(key.replace("Shift", "")) | ||
elif "Ctrl" in key: | ||
with self.keyboard.pressed(Key.ctrl): | ||
self.keyboard.tap(key.replace("Ctrl", "")) | ||
elif "Alt" in key: | ||
with self.keyboard.pressed(Key.alt): | ||
self.keyboard.tap(key.replace("Alt", "")) | ||
else: | ||
self.keyboard.tap(key) | ||
|
||
def input_word(self, word: str): | ||
self.keyboard.type(word) | ||
|
||
def esc(self): | ||
self.keyboard.tap(Key.esc) | ||
|
||
def enter(self): | ||
self.keyboard.tap(Key.enter) | ||
|
||
def space(self): | ||
self.keyboard.tap(Key.space) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
pydantic==1.8.2 | ||
mss==6.1.0 | ||
PyDirectInput==1.0.4 | ||
psutil==5.8.0 | ||
pytest==6.2.3 | ||
aiohttp==3.7.4.post0 | ||
pynput==1.7.3 | ||
numpy==1.20.2 | ||
aiohttp==3.7.4.post0 | ||
psutil==5.8.0 | ||
mss==6.1.0 | ||
Pillow==8.3.1 | ||
opencv-python | ||
opencv-python |