Skip to content

Commit 87b5e83

Browse files
author
welli7ngton
committed
MNT: Annotate all keyboard methods
1 parent 15fd15f commit 87b5e83

File tree

1 file changed

+54
-60
lines changed

1 file changed

+54
-60
lines changed

botcity/core/bot.py

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from PIL import Image, ImageGrab
1616
from psutil import Process
1717
from pynput.keyboard import Controller as KbController
18-
from pynput.keyboard import Key
18+
from pynput.keyboard import Key, KeyCode
1919
from pynput.mouse import Controller as MouseController
2020

2121
from . import config, cv2find
@@ -1121,7 +1121,7 @@ def type_key(self, text, interval=0):
11211121
"""
11221122
self.kb_type(text=text, interval=interval)
11231123

1124-
def kb_type(self, text, interval=0):
1124+
def kb_type(self, text: str, interval: Optional[int] = 0) -> None:
11251125
"""
11261126
Type a text char by char (individual key events).
11271127
@@ -1135,7 +1135,7 @@ def kb_type(self, text, interval=0):
11351135
self.sleep(interval)
11361136
self.sleep(config.DEFAULT_SLEEP_AFTER_ACTION)
11371137

1138-
def paste(self, text=None, wait=0):
1138+
def paste(self, text: Optional[str] = None, wait: Optional[int] = 0) -> None:
11391139
"""
11401140
Paste content from the clipboard.
11411141
@@ -1159,35 +1159,35 @@ def copy_to_clipboard(self, text, wait=0):
11591159
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
11601160
self.sleep(delay)
11611161

1162-
def tab(self, wait=0, presses=1):
1162+
def tab(self, wait: Optional[int] = 0, presses: int = 1) -> None:
11631163
"""
11641164
Press key Tab
11651165
11661166
Args:
11671167
wait (int, optional): Wait interval (ms) after task
1168-
presses (int, optional): Number of times to press the key. Defaults to 1.
1168+
presses (int): Number of times to press the key. Defaults to 1.
11691169
11701170
"""
11711171
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
1172-
for i in range(presses):
1172+
for _ in range(presses):
11731173
self._kb_controller.tap(Key.tab)
11741174
self.sleep(delay)
11751175

1176-
def enter(self, wait=0, presses=1):
1176+
def enter(self, wait: Optional[int] = 0, presses: int = 1) -> None:
11771177
"""
11781178
Press key Enter
11791179
11801180
Args:
11811181
wait (int, optional): Wait interval (ms) after task
1182-
presses (int, optional): Number of times to press the key. Defaults to 1.
1182+
presses (int): Number of times to press the key. Defaults to 1.
11831183
11841184
"""
11851185
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
1186-
for i in range(presses):
1186+
for _ in range(presses):
11871187
self._kb_controller.tap(Key.enter)
11881188
self.sleep(delay)
11891189

1190-
def key_right(self, wait=0):
1190+
def key_right(self, wait: Optional[int] = 0) -> None:
11911191
"""
11921192
Press key Right
11931193
@@ -1199,7 +1199,7 @@ def key_right(self, wait=0):
11991199
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
12001200
self.sleep(delay)
12011201

1202-
def key_enter(self, wait=0):
1202+
def key_enter(self, wait: Optional[int] = 0):
12031203
"""
12041204
Press key Enter
12051205
@@ -1209,7 +1209,7 @@ def key_enter(self, wait=0):
12091209
"""
12101210
self.enter(wait)
12111211

1212-
def key_end(self, wait=0):
1212+
def key_end(self, wait: Optional[int] = 0) -> None:
12131213
"""
12141214
Press key End
12151215
@@ -1221,7 +1221,7 @@ def key_end(self, wait=0):
12211221
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
12221222
self.sleep(delay)
12231223

1224-
def key_esc(self, wait=0):
1224+
def key_esc(self, wait: Optional[int] = 0) -> None:
12251225
"""
12261226
Press key Esc
12271227
@@ -1233,56 +1233,56 @@ def key_esc(self, wait=0):
12331233
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
12341234
self.sleep(delay)
12351235

1236-
def _key_fx(self, idx, wait=0):
1236+
def _key_fx(self, idx: KeyCode, wait: Optional[int] = 0) -> None:
12371237
"""
12381238
Press key F[idx] where idx is a value from 1 to 12
12391239
12401240
Args:
1241-
idx (int): F key index from 1 to 12
1241+
idx (str): F key index from 1 to 12
12421242
wait (int, optional): Wait interval (ms) after task
12431243
12441244
"""
12451245
self._kb_controller.tap(idx)
12461246
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
12471247
self.sleep(delay)
12481248

1249-
def key_f1(self, wait=0):
1249+
def key_f1(self, wait: int = 0) -> None:
12501250
self._key_fx(Key.f1, wait=wait)
12511251

1252-
def key_f2(self, wait=0):
1252+
def key_f2(self, wait: int = 0) -> None:
12531253
self._key_fx(Key.f2, wait=wait)
12541254

1255-
def key_f3(self, wait=0):
1255+
def key_f3(self, wait: int = 0) -> None:
12561256
self._key_fx(Key.f3, wait=wait)
12571257

1258-
def key_f4(self, wait=0):
1258+
def key_f4(self, wait: int = 0) -> None:
12591259
self._key_fx(Key.f4, wait=wait)
12601260

1261-
def key_f5(self, wait=0):
1261+
def key_f5(self, wait: int = 0) -> None:
12621262
self._key_fx(Key.f5, wait=wait)
12631263

1264-
def key_f6(self, wait=0):
1264+
def key_f6(self, wait: int = 0) -> None:
12651265
self._key_fx(Key.f6, wait=wait)
12661266

1267-
def key_f7(self, wait=0):
1267+
def key_f7(self, wait: int = 0) -> None:
12681268
self._key_fx(Key.f7, wait=wait)
12691269

1270-
def key_f8(self, wait=0):
1270+
def key_f8(self, wait: int = 0) -> None:
12711271
self._key_fx(Key.f8, wait=wait)
12721272

1273-
def key_f9(self, wait=0):
1273+
def key_f9(self, wait: int = 0) -> None:
12741274
self._key_fx(Key.f9, wait=wait)
12751275

1276-
def key_f10(self, wait=0):
1276+
def key_f10(self, wait: int = 0) -> None:
12771277
self._key_fx(Key.f10, wait=wait)
12781278

1279-
def key_f11(self, wait=0):
1279+
def key_f11(self, wait: int = 0) -> None:
12801280
self._key_fx(Key.f11, wait=wait)
12811281

1282-
def key_f12(self, wait=0):
1282+
def key_f12(self, wait: int = 0) -> None:
12831283
self._key_fx(Key.f12, wait=wait)
12841284

1285-
def hold_shift(self, wait=0):
1285+
def hold_shift(self, wait: Optional[int] = 0) -> None:
12861286
"""
12871287
Hold key Shift
12881288
@@ -1293,28 +1293,27 @@ def hold_shift(self, wait=0):
12931293
self._kb_controller.press(Key.shift)
12941294
self.sleep(wait)
12951295

1296-
def release_shift(self):
1296+
def release_shift(self) -> None:
12971297
"""
12981298
Release key Shift.
12991299
This method needs to be invoked after holding Shift or similar.
13001300
"""
13011301
self._kb_controller.release(Key.shift)
13021302
self.sleep(config.DEFAULT_SLEEP_AFTER_ACTION)
13031303

1304-
def alt_space(self, wait=0):
1304+
def alt_space(self, wait: Optional[int] = 0) -> None:
13051305
"""
13061306
Press keys Alt+Space
13071307
13081308
Args:
13091309
wait (int, optional): Wait interval (ms) after task
1310-
13111310
"""
13121311
with self._kb_controller.pressed(Key.alt):
13131312
self._kb_controller.tap(Key.space)
13141313
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
13151314
self.sleep(delay)
13161315

1317-
def maximize_window(self):
1316+
def maximize_window(self) -> None:
13181317
"""
13191318
Shortcut to maximize window on Windows OS.
13201319
"""
@@ -1515,7 +1514,9 @@ def control_s(self, wait=0):
15151514
"""
15161515
self.control_key(key_to_press="s", wait=wait)
15171516

1518-
def control_key(self, key_to_press: Union[str, Key], wait=0):
1517+
def control_key(
1518+
self, key_to_press: Union[str, KeyCode], wait: Optional[int] = 0
1519+
) -> None:
15191520
"""
15201521
Press CTRL and one more simple key to perform a keyboard shortcut
15211522
@@ -1535,7 +1536,7 @@ def control_key(self, key_to_press: Union[str, Key], wait=0):
15351536
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
15361537
self.sleep(delay)
15371538

1538-
def control_end(self, wait=0):
1539+
def control_end(self, wait: Optional[int] = 0) -> None:
15391540
"""
15401541
Press keys CTRL+End
15411542
@@ -1545,17 +1546,17 @@ def control_end(self, wait=0):
15451546
"""
15461547
self.control_key(key_to_press=Key.end, wait=wait)
15471548

1548-
def control_home(self, wait=0):
1549+
def control_home(self, wait: Optional[int] = 0) -> None:
15491550
"""
1550-
Press keys CTRL+Home
1551+
press keys ctrl+home
15511552
1552-
Args:
1553-
wait (int, optional): Wait interval (ms) after task
1553+
args:
1554+
wait (int, optional): wait interval (ms) after task
15541555
15551556
"""
15561557
self.control_key(key_to_press=Key.home, wait=wait)
15571558

1558-
def control_w(self, wait=0):
1559+
def control_w(self, wait: Optional[int] = 0) -> None:
15591560
"""
15601561
Press keys CTRL+W
15611562
@@ -1565,7 +1566,7 @@ def control_w(self, wait=0):
15651566
"""
15661567
self.control_key(key_to_press="w", wait=wait)
15671568

1568-
def control_shift_p(self, wait=0):
1569+
def control_shift_p(self, wait: Optional[int] = 0) -> None:
15691570
"""
15701571
Press keys CTRL+Shift+P
15711572
@@ -1581,7 +1582,7 @@ def control_shift_p(self, wait=0):
15811582
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
15821583
self.sleep(delay)
15831584

1584-
def control_shift_j(self, wait=0):
1585+
def control_shift_j(self, wait: Optional[int] = 0) -> None:
15851586
"""
15861587
Press keys CTRL+Shift+J
15871588
@@ -1597,7 +1598,7 @@ def control_shift_j(self, wait=0):
15971598
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
15981599
self.sleep(delay)
15991600

1600-
def shift_tab(self, wait=0):
1601+
def shift_tab(self, wait: Optional[int] = 0) -> None:
16011602
"""
16021603
Press keys Shift+Tab
16031604
@@ -1610,7 +1611,7 @@ def shift_tab(self, wait=0):
16101611
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
16111612
self.sleep(delay)
16121613

1613-
def get_clipboard(self):
1614+
def get_clipboard(self) -> str:
16141615
"""
16151616
Get the current content in the clipboard.
16161617
@@ -1619,7 +1620,7 @@ def get_clipboard(self):
16191620
"""
16201621
return pyperclip.paste()
16211622

1622-
def type_left(self, wait=0):
1623+
def type_left(self, wait: Optional[int] = 0) -> None:
16231624
"""
16241625
Press Left key
16251626
@@ -1631,7 +1632,7 @@ def type_left(self, wait=0):
16311632
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
16321633
self.sleep(delay)
16331634

1634-
def type_right(self, wait=0):
1635+
def type_right(self, wait: Optional[int] = 0) -> None:
16351636
"""
16361637
Press Right key
16371638
@@ -1643,7 +1644,7 @@ def type_right(self, wait=0):
16431644
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
16441645
self.sleep(delay)
16451646

1646-
def type_down(self, wait=0):
1647+
def type_down(self, wait: Optional[int] = 0) -> None:
16471648
"""
16481649
Press Down key
16491650
@@ -1655,85 +1656,78 @@ def type_down(self, wait=0):
16551656
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
16561657
self.sleep(delay)
16571658

1658-
def type_up(self, wait=0):
1659+
def type_up(self, wait: Optional[int] = 0) -> None:
16591660
"""
16601661
Press Up key
16611662
16621663
Args:
16631664
wait (int, optional): Wait interval (ms) after task
1664-
16651665
"""
16661666
self._kb_controller.tap(Key.up)
16671667
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
16681668
self.sleep(delay)
16691669

1670-
def type_windows(self, wait=0):
1670+
def type_windows(self, wait: Optional[int] = 0) -> None:
16711671
"""
16721672
Press Win logo key
16731673
16741674
Args:
16751675
wait (int, optional): Wait interval (ms) after task
1676-
16771676
"""
16781677
self._kb_controller.tap(Key.cmd)
16791678
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
16801679
self.sleep(delay)
16811680

1682-
def page_up(self, wait=0):
1681+
def page_up(self, wait: Optional[int] = 0) -> None:
16831682
"""
16841683
Press Page Up key
16851684
16861685
Args:
16871686
wait (int, optional): Wait interval (ms) after task
1688-
16891687
"""
16901688
self._kb_controller.tap(Key.page_up)
16911689
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
16921690
self.sleep(delay)
16931691

1694-
def page_down(self, wait=0):
1692+
def page_down(self, wait: Optional[int] = 0) -> None:
16951693
"""
16961694
Press Page Down key
16971695
16981696
Args:
16991697
wait (int, optional): Wait interval (ms) after task
1700-
17011698
"""
17021699
self._kb_controller.tap(Key.page_down)
17031700
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
17041701
self.sleep(delay)
17051702

1706-
def space(self, wait=0):
1703+
def space(self, wait: Optional[int] = 0) -> None:
17071704
"""
17081705
Press Space key
17091706
17101707
Args:
17111708
wait (int, optional): Wait interval (ms) after task
1712-
17131709
"""
17141710
self._kb_controller.tap(Key.space)
17151711
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
17161712
self.sleep(delay)
17171713

1718-
def backspace(self, wait=0):
1714+
def backspace(self, wait: Optional[int] = 0) -> None:
17191715
"""
17201716
Press Backspace key
17211717
17221718
Args:
17231719
wait (int, optional): Wait interval (ms) after task
1724-
17251720
"""
17261721
self._kb_controller.tap(Key.backspace)
17271722
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)
17281723
self.sleep(delay)
17291724

1730-
def delete(self, wait=0):
1725+
def delete(self, wait: Optional[int] = 0) -> None:
17311726
"""
17321727
Press Delete key
17331728
17341729
Args:
17351730
wait (int, optional): Wait interval (ms) after task
1736-
17371731
"""
17381732
self._kb_controller.tap(Key.delete)
17391733
delay = max(0, wait or config.DEFAULT_SLEEP_AFTER_ACTION)

0 commit comments

Comments
 (0)