'How do I detect if shift is held while pressing "7" to make division
I am trying to make a calculator, but I keep running into the same issue.
Every time I press 7 it runs the function "sevenCmd" but also "divisionCmd" even tho I'm not holding shift.
I am using the "keyboard" module
keyboard.add_hotkey('+', lambda: plusCmd())
keyboard.add_hotkey('-', lambda: minusCmd())
keyboard.add_hotkey('*', lambda: timesCmd())
keyboard.add_hotkey('/', lambda: divisionCmd()) #Problems on this line
keyboard.add_hotkey('Enter', lambda: equalsCmd())
keyboard.add_hotkey('C', lambda: clearCmd())
keyboard.add_hotkey(',', lambda: commaCmd())
keyboard.add_hotkey('.', lambda: commaCmd())
keyboard.add_hotkey('Backspace', lambda: deleteCmd())
keyboard.add_hotkey('1', lambda: oneCmd())
keyboard.add_hotkey('2', lambda: twoCmd())
keyboard.add_hotkey('3', lambda: threeCmd())
keyboard.add_hotkey('4', lambda: fourCmd())
keyboard.add_hotkey('5', lambda: fiveCmd())
keyboard.add_hotkey('6', lambda: sixCmd())
keyboard.add_hotkey('7', lambda: sevenCmd())
keyboard.add_hotkey('8', lambda: eightCmd())
keyboard.add_hotkey('9', lambda: nineCmd())
keyboard.add_hotkey('0', lambda: zeroCmd())
Solution 1:[1]
Just put in some logic in the division hotkey to check whether or not shift is pressed
keyboard.add_hotkey('7 + shift', lambda: divisionCmd()) #Problems on this line
this works
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
