문제

I'm trying to toggle caps lock on/off when the two shift buttons are held down for a second. I've tried using the virtkey module, but it's not working. That module does work for other keys though, so I don't think I'm using the module incorrectly.

Does anybody have a way for doing this?

Just to be clear, I want to actually toggle caps lock on/off and not just the LED.

Thanks!

도움이 되었습니까?

해결책

This works for me (turns the led on and off as well as enable/disable caps)

import virtkey

v = virtkey.virtkey()
v.press_keycode(66)
v.release_keycode(66)  # first release doesn't release it
v.release_keycode(66)

Here are some more examples

v.press_keycode(66)    # turns capslock on
v.release_keycode(66)
v.press_keycode(66)    # turns capslock off
v.release_keycode(66)

You can also get a toggle like behaviour just using release_keycode

v.release_keycode(66)  # toggles capslock
v.release_keycode(66)  # toggles back again capslock

다른 팁

Funny thing. I gave virtkey a try in the interpreter, and it seemed like it was working. After calling press_keycode(50), my machine acts like caps lock has been pressed (Ubuntu 9.10, python-virtkey .50ubuntu2). If I release the key- release_keycode(50)- it acts like nothing has happened.

import virtkey

v = virtkey.virtkey()
v.press_keycode(50)

if run as a script, leaves the caps key pressed for a virtual terminal tab. Very annoying.

Have you looked into the xvkbd command? It's an X virtual keyboard with command line options, and worst case you could call it from python. Another idea to look into is xmodmap, which lets you re-map keys in X. See this post on SU for an example.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top