Skip to content

Commit

Permalink
updated keyboard for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
DorskFR committed Aug 13, 2021
1 parent c3de7ae commit 102ee09
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 31 deletions.
39 changes: 13 additions & 26 deletions LPBv2/LPBv2/controller/devices/keyboard.py
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()
36 changes: 36 additions & 0 deletions LPBv2/LPBv2/controller/devices/keyboard_pydirectinput.py
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")
30 changes: 30 additions & 0 deletions LPBv2/LPBv2/controller/devices/keyboard_pynput.py
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)
1 change: 0 additions & 1 deletion LPBv2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from LPBv2.common import debug_coro, cls
import asyncio


@debug_coro
async def main():
bot = LeaguePyBot(autoplay=True)
Expand Down
9 changes: 5 additions & 4 deletions LPBv2/requirements.txt
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

0 comments on commit 102ee09

Please sign in to comment.