Python: how to block keys for everything except the keyboard module?
📁 python, вопрос, боты, ии
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
Интересные статьи
CI/CD for TypeScript Projects: GitHub Actions
How to Count Occurrences of a Character or Substring in a String in C#: 5 Ways
C# Integration with Other Languages: From P/Invoke to Python and JavaScript
Writing Documentation for a Swift Project: From A to Z