Python Forum
Check for Caps Lock
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check for Caps Lock
#1
Hi,

In a class I use the code below to print in the console if the Caps Lock is on or not.
Instead of printing, I'd like to compare the e.state and if it's =="Caps Lock" then dispaly a msg:
messagebox.showinfo ( "Warning" , "Caps Lock is activated")

How do I do that?
TIA


mods = {
    0x0001: 'Shift',
    0x0002: 'Caps Lock',
    0x0004: 'Control',
    0x0008: 'Left-hand Alt',
    0x0010: 'Num Lock',
    0x0080: 'Right-hand Alt',
    0x0100: 'Mouse button 1',
    0x0200: 'Mouse button 2',
    0x0400: 'Mouse button 3'
}
self.username.bind('<Key>', lambda e: print('Mods:', mods.get( e.state, None )))
Reply
#2
you can also use a keyboard listener such as https://pypi.org/project/keyboard-listener/
there are many to choose from: https://pypi.org/search/?q=keyboard+%2B+listener
ebolisa likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Treeview - How to lock columns taratata2020 0 3,334 Mar-29-2020, 03:30 PM
Last Post: taratata2020
  [Tkinter] Lock Text Widget height Oxylium 3 4,216 Feb-14-2019, 10:13 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020