Python: how to block keys for everything except the keyboard module?
📁 Advanced Python Topics, question, bots, AI
I have a program that should substitute certain characters and character combinations when certain keys are pressed:
import keyboardwhile True: hotkey = keyboard.read_hotkey(suppress=False) if hotkey == 'j+k': keyboard.write('j + k')(I'm not using keyboard.add_hotkey() because in the future my plans involve not specific hotkeys, but checking for the presence of certain keys in hotkey. But this doesn't change the situation: add_hotkey() behaves the same way) I expect that when running this program, when I simultaneously press j
Solution using the extended Euclidean algorithm. The method using exponentiation requires computing Euler's totient function.
Edit: Following @Eduard's hint, removed extra steps to get a positive result (x may be negative after the Euclidean algorithm), which are not required in Python
def gcdExtended(a, b): if a == 0 : retu b,0,1 gcd,x1,y1 = gcdExtended(b%a, a) x = y1 - (b//a) * x1 y = x1 retu gcd,x,ym, a = map(int, input Log in to leave an answer
Blogs
PHP Security: How to Protect Your Site from SQL Injections and XSS
Search in Rust: Finding the Index of an Array Element with Maximum Performance
Arrays in Swift: 5 Fatal Errors When Adding Elements (and How to Avoid Them)
String vs string in TypeScript: which to choose for speed?