-
Notifications
You must be signed in to change notification settings - Fork 0
/
keytouch.py
63 lines (51 loc) · 1.81 KB
/
keytouch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import win32com.client
import time
import logging
import argparse
# Dictionary for mapping friendly names to dead key characters
DEAD_KEYS = {
"shift": "+",
"alt": "%",
"ctrl": "^",
"capslock": "{CAPSLOCK}"
}
def press_dead_key(interval, key):
"""
Presses the specified dead key at regular intervals indefinitely.
Args:
interval (int): Time in seconds between key presses.
key (str): The key to be pressed, as recognized by `SendKeys`.
"""
shell = win32com.client.Dispatch("WScript.Shell")
while True:
shell.SendKeys(key) # Simulates the press of the specified key
logging.info(f"{key} key pressed")
time.sleep(interval)
def main():
"""
Main entry point of the script. Parses command-line arguments, configures logging, and starts key pressing.
"""
# Setting up argument parser for command-line parameters
parser = argparse.ArgumentParser(description="Simulate pressing a dead key at regular intervals.")
parser.add_argument(
"--interval",
type=int,
default=60,
help="Time interval between key presses in seconds (default: 60)"
)
parser.add_argument(
"--key",
type=str,
default="shift",
choices=DEAD_KEYS.keys(),
help="The dead key to press (choices: shift, alt, ctrl, capslock). Default is 'shift'."
)
args = parser.parse_args()
# Configuring basic logging to standard output
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# Getting the correct key character from DEAD_KEYS dictionary
dead_key = DEAD_KEYS[args.key]
# Starting the key pressing function with the provided interval and key
press_dead_key(args.interval, dead_key)
if __name__ == "__main__":
main()