How do I use the Python module “keyboardleds” to determine Caps Lock state?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1
















  1. I want my system to ascertain the state of Caps Lock (is it on or off) by
    inspecting the keyboard DIRECTLY. After much searching, I understand that this
    can be done in Python by using the module "keyboardleds".



    I'm not familiar with Python, so my main request is, can you tell me how to
    use the module keyboardleds in a Python script, so that it tells me what the
    state of Caps Lock is?
    The Python version on my system is 2.7.3rc2.




  2. The information I've found about "keyboardleds", is too technical for me to
    understand. Also an example I found of how keyboardleds is used, uses complex
    python programming that I don't understand either. Also, the example I've looked
    at uses keyboardleds for one of its other purposes, not for the purpose I want
    (ie determining the state of Caps Lock).



    I don't even know what the "import" commands mean at the beginning of the
    example script, and whether I need all of them.



    I would be most grateful if you could tell me what python commands I need to
    use, and what detailed contents I put in them.




  3. I just need the python script to give an exit status of zero (true) if Caps
    Lock is off, and an exit status of 1 (false) if Caps Lock is on.



    Say the python script is called "capslockstate". Then I'll use it in a bash script as follows:



    if capslockstate
    then
    <perform an action based on the fact that Caps Lock is off>
    else
    <perform an action based on the fact that Caps Lock is on>
    fi



  4. SIGNIFICANT I BELIEVE:



    Regarding accessing the keyboard, the info I've found refers to using either /dev/console, /dev/input/event*, and /dev/input/by-path/*-event-kbd. On my system, all 3 of these exist. In the latter 2 cases, I've got the following on my system:



    /dev/input/event0 through to /dev/input/event9.

    /dev/input/by-path/platform-i8042-serio-0-event-kbd
    ### ie only ^this^ one item exists


    The "by-path" is the actual directory name.



    I believe that one of the above 2 "/dev/input/..." entities is what I need to use (as opposed to /dev/console), even though I don't understand the ins and outs of it.




  5. Below are the websites where I found the information on keyboardleds:




    1. The first site that put me onto using keyboardleds (with examples that are too complex for me):



      https://stackoverflow.com/questions/15625367/alternative-approaches-for-accessing-keyboard-leds-in-linux-with-python



      What particularly interested me on this site is the comment "the program [keyboardleds] accesses the keyboard DIRECTLY."




    2. Official documentation I believe, on keyboardleds (too complex for me to understand):



      https://python-keyboardleds.readthedocs.org/en/0.3.3/




    3. The site of the author of keyboardleds:



      http://jwilk.net/software/python-keyboardleds












share|improve this question
























  • why python...? if it is a linux system with the basic util-linux package installed, then you probably want setleds.

    – mikeserv
    Sep 26 '15 at 21:44











  • Please log in properly. If you're having problems with that, see here

    – terdon
    Sep 27 '15 at 15:05

















1
















  1. I want my system to ascertain the state of Caps Lock (is it on or off) by
    inspecting the keyboard DIRECTLY. After much searching, I understand that this
    can be done in Python by using the module "keyboardleds".



    I'm not familiar with Python, so my main request is, can you tell me how to
    use the module keyboardleds in a Python script, so that it tells me what the
    state of Caps Lock is?
    The Python version on my system is 2.7.3rc2.




  2. The information I've found about "keyboardleds", is too technical for me to
    understand. Also an example I found of how keyboardleds is used, uses complex
    python programming that I don't understand either. Also, the example I've looked
    at uses keyboardleds for one of its other purposes, not for the purpose I want
    (ie determining the state of Caps Lock).



    I don't even know what the "import" commands mean at the beginning of the
    example script, and whether I need all of them.



    I would be most grateful if you could tell me what python commands I need to
    use, and what detailed contents I put in them.




  3. I just need the python script to give an exit status of zero (true) if Caps
    Lock is off, and an exit status of 1 (false) if Caps Lock is on.



    Say the python script is called "capslockstate". Then I'll use it in a bash script as follows:



    if capslockstate
    then
    <perform an action based on the fact that Caps Lock is off>
    else
    <perform an action based on the fact that Caps Lock is on>
    fi



  4. SIGNIFICANT I BELIEVE:



    Regarding accessing the keyboard, the info I've found refers to using either /dev/console, /dev/input/event*, and /dev/input/by-path/*-event-kbd. On my system, all 3 of these exist. In the latter 2 cases, I've got the following on my system:



    /dev/input/event0 through to /dev/input/event9.

    /dev/input/by-path/platform-i8042-serio-0-event-kbd
    ### ie only ^this^ one item exists


    The "by-path" is the actual directory name.



    I believe that one of the above 2 "/dev/input/..." entities is what I need to use (as opposed to /dev/console), even though I don't understand the ins and outs of it.




  5. Below are the websites where I found the information on keyboardleds:




    1. The first site that put me onto using keyboardleds (with examples that are too complex for me):



      https://stackoverflow.com/questions/15625367/alternative-approaches-for-accessing-keyboard-leds-in-linux-with-python



      What particularly interested me on this site is the comment "the program [keyboardleds] accesses the keyboard DIRECTLY."




    2. Official documentation I believe, on keyboardleds (too complex for me to understand):



      https://python-keyboardleds.readthedocs.org/en/0.3.3/




    3. The site of the author of keyboardleds:



      http://jwilk.net/software/python-keyboardleds












share|improve this question
























  • why python...? if it is a linux system with the basic util-linux package installed, then you probably want setleds.

    – mikeserv
    Sep 26 '15 at 21:44











  • Please log in properly. If you're having problems with that, see here

    – terdon
    Sep 27 '15 at 15:05













1












1








1









  1. I want my system to ascertain the state of Caps Lock (is it on or off) by
    inspecting the keyboard DIRECTLY. After much searching, I understand that this
    can be done in Python by using the module "keyboardleds".



    I'm not familiar with Python, so my main request is, can you tell me how to
    use the module keyboardleds in a Python script, so that it tells me what the
    state of Caps Lock is?
    The Python version on my system is 2.7.3rc2.




  2. The information I've found about "keyboardleds", is too technical for me to
    understand. Also an example I found of how keyboardleds is used, uses complex
    python programming that I don't understand either. Also, the example I've looked
    at uses keyboardleds for one of its other purposes, not for the purpose I want
    (ie determining the state of Caps Lock).



    I don't even know what the "import" commands mean at the beginning of the
    example script, and whether I need all of them.



    I would be most grateful if you could tell me what python commands I need to
    use, and what detailed contents I put in them.




  3. I just need the python script to give an exit status of zero (true) if Caps
    Lock is off, and an exit status of 1 (false) if Caps Lock is on.



    Say the python script is called "capslockstate". Then I'll use it in a bash script as follows:



    if capslockstate
    then
    <perform an action based on the fact that Caps Lock is off>
    else
    <perform an action based on the fact that Caps Lock is on>
    fi



  4. SIGNIFICANT I BELIEVE:



    Regarding accessing the keyboard, the info I've found refers to using either /dev/console, /dev/input/event*, and /dev/input/by-path/*-event-kbd. On my system, all 3 of these exist. In the latter 2 cases, I've got the following on my system:



    /dev/input/event0 through to /dev/input/event9.

    /dev/input/by-path/platform-i8042-serio-0-event-kbd
    ### ie only ^this^ one item exists


    The "by-path" is the actual directory name.



    I believe that one of the above 2 "/dev/input/..." entities is what I need to use (as opposed to /dev/console), even though I don't understand the ins and outs of it.




  5. Below are the websites where I found the information on keyboardleds:




    1. The first site that put me onto using keyboardleds (with examples that are too complex for me):



      https://stackoverflow.com/questions/15625367/alternative-approaches-for-accessing-keyboard-leds-in-linux-with-python



      What particularly interested me on this site is the comment "the program [keyboardleds] accesses the keyboard DIRECTLY."




    2. Official documentation I believe, on keyboardleds (too complex for me to understand):



      https://python-keyboardleds.readthedocs.org/en/0.3.3/




    3. The site of the author of keyboardleds:



      http://jwilk.net/software/python-keyboardleds












share|improve this question

















  1. I want my system to ascertain the state of Caps Lock (is it on or off) by
    inspecting the keyboard DIRECTLY. After much searching, I understand that this
    can be done in Python by using the module "keyboardleds".



    I'm not familiar with Python, so my main request is, can you tell me how to
    use the module keyboardleds in a Python script, so that it tells me what the
    state of Caps Lock is?
    The Python version on my system is 2.7.3rc2.




  2. The information I've found about "keyboardleds", is too technical for me to
    understand. Also an example I found of how keyboardleds is used, uses complex
    python programming that I don't understand either. Also, the example I've looked
    at uses keyboardleds for one of its other purposes, not for the purpose I want
    (ie determining the state of Caps Lock).



    I don't even know what the "import" commands mean at the beginning of the
    example script, and whether I need all of them.



    I would be most grateful if you could tell me what python commands I need to
    use, and what detailed contents I put in them.




  3. I just need the python script to give an exit status of zero (true) if Caps
    Lock is off, and an exit status of 1 (false) if Caps Lock is on.



    Say the python script is called "capslockstate". Then I'll use it in a bash script as follows:



    if capslockstate
    then
    <perform an action based on the fact that Caps Lock is off>
    else
    <perform an action based on the fact that Caps Lock is on>
    fi



  4. SIGNIFICANT I BELIEVE:



    Regarding accessing the keyboard, the info I've found refers to using either /dev/console, /dev/input/event*, and /dev/input/by-path/*-event-kbd. On my system, all 3 of these exist. In the latter 2 cases, I've got the following on my system:



    /dev/input/event0 through to /dev/input/event9.

    /dev/input/by-path/platform-i8042-serio-0-event-kbd
    ### ie only ^this^ one item exists


    The "by-path" is the actual directory name.



    I believe that one of the above 2 "/dev/input/..." entities is what I need to use (as opposed to /dev/console), even though I don't understand the ins and outs of it.




  5. Below are the websites where I found the information on keyboardleds:




    1. The first site that put me onto using keyboardleds (with examples that are too complex for me):



      https://stackoverflow.com/questions/15625367/alternative-approaches-for-accessing-keyboard-leds-in-linux-with-python



      What particularly interested me on this site is the comment "the program [keyboardleds] accesses the keyboard DIRECTLY."




    2. Official documentation I believe, on keyboardleds (too complex for me to understand):



      https://python-keyboardleds.readthedocs.org/en/0.3.3/




    3. The site of the author of keyboardleds:



      http://jwilk.net/software/python-keyboardleds









python capslock






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 '17 at 12:39









Community

1




1










asked Sep 26 '15 at 21:12









davedave

61




61












  • why python...? if it is a linux system with the basic util-linux package installed, then you probably want setleds.

    – mikeserv
    Sep 26 '15 at 21:44











  • Please log in properly. If you're having problems with that, see here

    – terdon
    Sep 27 '15 at 15:05

















  • why python...? if it is a linux system with the basic util-linux package installed, then you probably want setleds.

    – mikeserv
    Sep 26 '15 at 21:44











  • Please log in properly. If you're having problems with that, see here

    – terdon
    Sep 27 '15 at 15:05
















why python...? if it is a linux system with the basic util-linux package installed, then you probably want setleds.

– mikeserv
Sep 26 '15 at 21:44





why python...? if it is a linux system with the basic util-linux package installed, then you probably want setleds.

– mikeserv
Sep 26 '15 at 21:44













Please log in properly. If you're having problems with that, see here

– terdon
Sep 27 '15 at 15:05





Please log in properly. If you're having problems with that, see here

– terdon
Sep 27 '15 at 15:05










1 Answer
1






active

oldest

votes


















0














I have been having good luck using:



from win32con import VK_CAPITAL
if GetKeyState(VK_CAPITAL) == 1:
print ("CAPS Lock is on.")
elif GetKeyState(VK_CAPITAL) == 0:
print ("CAPS Lock is off.")


This is on a windows computer with Python3, so not 100% sure if it works on linux also, but worth noting as an option for those needing to do this on windows, this works for sure in that case - I've seen it myself.



Randy






share|improve this answer























  • As the module names suggest, win32api and win32con are Windows exclusive and are not available on *NIX. I do think, however, the answer gives a good insight into how that is done on other operation systems.

    – undercat
    Mar 14 at 11:27












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f232252%2fhow-do-i-use-the-python-module-keyboardleds-to-determine-caps-lock-state%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I have been having good luck using:



from win32con import VK_CAPITAL
if GetKeyState(VK_CAPITAL) == 1:
print ("CAPS Lock is on.")
elif GetKeyState(VK_CAPITAL) == 0:
print ("CAPS Lock is off.")


This is on a windows computer with Python3, so not 100% sure if it works on linux also, but worth noting as an option for those needing to do this on windows, this works for sure in that case - I've seen it myself.



Randy






share|improve this answer























  • As the module names suggest, win32api and win32con are Windows exclusive and are not available on *NIX. I do think, however, the answer gives a good insight into how that is done on other operation systems.

    – undercat
    Mar 14 at 11:27
















0














I have been having good luck using:



from win32con import VK_CAPITAL
if GetKeyState(VK_CAPITAL) == 1:
print ("CAPS Lock is on.")
elif GetKeyState(VK_CAPITAL) == 0:
print ("CAPS Lock is off.")


This is on a windows computer with Python3, so not 100% sure if it works on linux also, but worth noting as an option for those needing to do this on windows, this works for sure in that case - I've seen it myself.



Randy






share|improve this answer























  • As the module names suggest, win32api and win32con are Windows exclusive and are not available on *NIX. I do think, however, the answer gives a good insight into how that is done on other operation systems.

    – undercat
    Mar 14 at 11:27














0












0








0







I have been having good luck using:



from win32con import VK_CAPITAL
if GetKeyState(VK_CAPITAL) == 1:
print ("CAPS Lock is on.")
elif GetKeyState(VK_CAPITAL) == 0:
print ("CAPS Lock is off.")


This is on a windows computer with Python3, so not 100% sure if it works on linux also, but worth noting as an option for those needing to do this on windows, this works for sure in that case - I've seen it myself.



Randy






share|improve this answer













I have been having good luck using:



from win32con import VK_CAPITAL
if GetKeyState(VK_CAPITAL) == 1:
print ("CAPS Lock is on.")
elif GetKeyState(VK_CAPITAL) == 0:
print ("CAPS Lock is off.")


This is on a windows computer with Python3, so not 100% sure if it works on linux also, but worth noting as an option for those needing to do this on windows, this works for sure in that case - I've seen it myself.



Randy







share|improve this answer












share|improve this answer



share|improve this answer










answered Jul 29 '18 at 14:39









Randy Mad-DogRandy Mad-Dog

1




1












  • As the module names suggest, win32api and win32con are Windows exclusive and are not available on *NIX. I do think, however, the answer gives a good insight into how that is done on other operation systems.

    – undercat
    Mar 14 at 11:27


















  • As the module names suggest, win32api and win32con are Windows exclusive and are not available on *NIX. I do think, however, the answer gives a good insight into how that is done on other operation systems.

    – undercat
    Mar 14 at 11:27

















As the module names suggest, win32api and win32con are Windows exclusive and are not available on *NIX. I do think, however, the answer gives a good insight into how that is done on other operation systems.

– undercat
Mar 14 at 11:27






As the module names suggest, win32api and win32con are Windows exclusive and are not available on *NIX. I do think, however, the answer gives a good insight into how that is done on other operation systems.

– undercat
Mar 14 at 11:27


















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f232252%2fhow-do-i-use-the-python-module-keyboardleds-to-determine-caps-lock-state%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay