TanGentleman / KeyMaster

A comprehensive toolkit for python classes and easy to use scripts for logging, analyzing, and simulating keystrokes.
MIT License
1 stars 0 forks source link

caps lock being ignored in KeystrokeList #71

Closed TanGentleman closed 5 months ago

TanGentleman commented 5 months ago

When collecting user input, caps lock seems to work, but I've intentionally disabled it when it comes to representing the string in KeystrokeList objects. Is this a bug?

To replicate:


from utils.validation import Keystroke, KeystrokeList
>>> keystrokes = KeystrokeList([Keystroke('a',None),Keystroke('Key.caps',0.1),Keystroke('"b"',0.2)])
>>> keystrokes.to_string()
'ab'
TanGentleman commented 5 months ago

Working on a patch that seems promising. I've added a method process_caps_lock() to KeystrokeList.

# Get keystrokes by simulating a string
gen = Generate()
gen.disable()
keys = gen.simulate_string('hippopotamus') # Type KeystrokeList

# Test process_caps_lock
# Replace first letter with caps lock
keys[0] = Keystroke('Key.caps_lock', None)
keys.process_caps_lock()
assert keys.to_string() == 'IPPOPOTAMUS'
keys.process_caps_lock()
assert keys.to_string() == 'ippopotamus'
# Replace the "u" with caps lock
keys[-2] = Keystroke('Key.caps_lock', 0.2222)
keys.process_caps_lock()
assert keys.to_string() == 'IPPOPOTAMs'
# Works as expected!

I'm going to add this as a step step when logging the KeystrokeList in classes/converter.