How do you check weather or not capslock is on on pygame


I found certain code in a pygame program, this to be exact:

caplock = False for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.CAPSLOCK: capslock = True if event.type == pygame.KEYUP: if event.key == pygame.CAPSLOCK: capslock = False

when you press "caps lock" while it is off, capslock is


and when you press "caps lock" while it is on, capslock is


Instead of making capslock equal to False at the beginning, how can I make it equal to True if capslock is already on or False if it is already off?


On Linux (tested on Linux Mint 18.1 with Python 3.6) you can use:

import subprocess if subprocess.check_output('xset q | grep LED', shell=True)[65] == 50 : capslock = False if subprocess.check_output('xset q | grep LED', shell=True)[65] == 51 : capslock = True print( "capslock ON is : ", capslock )

If it doesn't work, check which values subprocess.check_output() gives you if CapsLock is ON and if CapsLock is OFF. Theoretically it should be 0 and 1, not 50, 51, but on my box it is 50, 51.

You can also take a look at <a href="https://stackoverflow.com/questions/13129804/python-how-to-get-current-keylock-status" rel="nofollow">"Python - How to get current keylock status?"</a> for further information.

And YES, I think also you need a keypress event from Pygame to know the status of the keys, so to know it in advance you have to use a method from outside of Pygame.


  • SDL library in linux
  • G_Settings apply changes
  • Numpy/Scipy broadcast calculating scalar product for a certain elements
  • Using JavaScript to create a Chrome-style alert
  • Unable to connect to Docker container from host
  • Eclipse in adt-bundle for android development freezes by auto complete
  • How do you check weather or not capslock is on on pygame
  • Jupyter Notebook Server password invalid
  • Android app not responding at Calender.getInstance
  • Build tools - why so many versions?
  • What happens when you dereference a postincrement C
  • Check python function determine isogram from codewars
  • Android twitter user/show (user information) migration version 1 to 1.1
  • Sublime only opens in Sublimerge view
  • Extract values from a correlation matrix according to their p-value in a second matrix
  • Customizing slider track images
  • Selenium: How do I start Chrome with RailsPanel Extension loaded?
  • jconsole to connect to apachemq
  • Using LOAD DATA INFILE with arabic data
  • Fix pixman_region_init_rect bug
  • Sharing files between container and host
  • Detecting All Caps in a string
  • IIS Session timeout and Forms Authentication loop
  • Login-AzureRmAccount command not working from hosted c# application
  • Close button for AdMob banner
  • How ignore any files using HHVM proxygen rewrite rules?
  • mysql table locked after php crashes
  • How can I stop my python script when another python script is running?
  • Full 8 bit adder, illogical output
  • C#: Import/Export Settings into/from a File
  • Lock Horizontal View
  • uml Composition relationships to RDF and OWL
  • Azure table store snapshot/backup capability
  • Trying to get the char code of ENTER key
  • xtable package: Skipping some rows in the output
  • Thread safety of a fluent like class using clone() and non final fields
  • Ionic 2 storage is not cleaning up on uninstall - Only for signed APK
  • Why value captured by reference in lambda is broken? [duplicate]
  • Change JButton Shape while respecting Look And Feel
  • ExecuteAsync RestSharp to allow backgroundWorker CancellationPending c#