0

Does somebody knows a way to check if Capslock is on using Python 2.6?

EDIT: I've already seen this solution Python - How to get current keylock status?, but it gave me a "string out of range" error. If you know why it would be helpful as well!

Community
  • 1
  • 1
Orel Regev
  • 19
  • 3
  • 2
    duplicate: http://stackoverflow.com/questions/13129804/python-how-to-get-current-keylock-status – axblount Apr 02 '15 at 17:36
  • First of all, thank you for the fast comment! I've tried using this but it gave me "string out of range" error. I have just copied it.. Do you know why? – Orel Regev Apr 02 '15 at 17:43
  • No, we don't, since we don't know what the output of the command looks like on your system. – Ignacio Vazquez-Abrams Apr 02 '15 at 17:49
  • I really don't understand what you mean. I have no output.. Just an error. Are we talking about the same solution using module commands? – Orel Regev Apr 02 '15 at 18:15
  • What do you see when you run `xset q` on the command line? If it's something like `xset: command not found`, well there you go. – Josh Kupershmidt Apr 02 '15 at 19:04
  • I think the long and short of it is that there's not an OS-agnostic solution to what you want. Any solutions either rely on shelling to an external command like `xset` or rely on native API interface modules of some sort or the other. – geoelectric Apr 02 '15 at 19:55
  • Josh - You're right, I got 'is not recognized as an internal or external command'. Can I do something with it? Sorry for not knowing anything about this module.. I didn't really get it. And I guess that every solution that will work, even with a bit work besides just copying code, can be helpful – Orel Regev Apr 03 '15 at 09:09
  • @OrelRegev you would need to install [xset](http://www.x.org/archive/X11R7.5/doc/man/man1/xset.1.html). The installation process will vary by operating system, and you haven't told us what OS you are using. Either way, this question sure seems to be a duplicate of http://stackoverflow.com/questions/13129804/python-how-to-get-current-keylock-status – Josh Kupershmidt Apr 03 '15 at 15:28

1 Answers1

0

import commands

CapsLock_status=commands.getoutput('xset q | grep Caps')[21:24]

print "CapsLock status is : %s" %CapsLock_status