skkeeper / linux-clicky

Adds sounds to your keyboard presses
MIT License
47 stars 19 forks source link

The script stops working after a few key presses #1

Open fehmud opened 12 years ago

fehmud commented 12 years ago

Hello,

thank you for writing and sharing this useful utility.

After checking that all the dependencies were satisfied, I tried running the script on my system, but it stopped working after a few key presses. Rebooting fixed the issue, but only momentarily.

I tried more than once, with the same results.

Launching the gnome-system-monitor showed a lot of "play" and "sh" sleeping processes and a "python" one. I was able to end only the "python" process.

I wish I were a Python developer, to be able to give more help.

Cheers.

Software:

Python: 2.7.3 Debian GNU/Linux: 6.0.5 Gnome Version: 2.30.2 Linux Kernel: 2.6.32-5-686

skkeeper commented 12 years ago

Sorry for the late reply.

If you run it in the CLI does it output any sort of errors and/or Exceptions? If so please post them here. I haven't touched the script in a while something might have changed on the dependency chain.

fehmud commented 12 years ago

On 07/29/2012 11:43 AM, Fábio André Damas wrote:

Sorry for the late reply.

If you run it in the CLI does it output any sort of errors and/or Exceptions? If so please post them here. I haven't touched the script in a while something might have changed on the dependency chain.


Reply to this email directly or view it on GitHub: https://github.com/skkeeper/linux-clicky/issues/1#issuecomment-7351402

Thank you for replying.

I always ran the script from the terminal, and neither warnings nor errors were displayed.

Cheers.

skkeeper commented 12 years ago

Hello again,

If you can please re-download the project and run it again, it should output some type of error now.

Thanks for your time :)

fehmud commented 12 years ago

Done. Here it is what I got:

$ sudo python main.py [sudo] password for egarrulo:

ttttttttCTRL + C Detected. Exiting ... Ignore any errors after this message. [1]+ Stopped sudo python main.py ## The ttttttt is me pressing the T key to check whether the program was working. It was, and this time it lasted more: I switched to another application and typed a few sentences. Then I heard no more clicks, and as you can see I pressed Ctrl+C to exit the program, but I couldn't get back to the console until I pressed Ctrl+D (where you see "[1]+ Stopped"). However, this time there were no zombie processes. I think I had a broken Python installation before that I have recently fixed (i.e. multiple installations with a shared environment). Sorry for not fixing that before testing your application, but I'm a Python novice and I wasn't even aware that the environment was broken. So far, so good. Actually, I tried writing a program similar to yours myself, using Python Xlib, but despite being able to trap keyboard events, I wasn't able to pass them to applications. I'm attaching the code I used, in case you may want to use it in your project, as my code does not require root privileges. I was interested in detecting the releasing of modifiers, but I guess generalizing the code shouldn't be difficult. The code comes from the Pykeylogger project (pykeylogger.sourceforge.net) to which you may be interested in having a look. Cheers. ## #! /usr/bin/env python from Xlib.display import Display from Xlib import X Control_R = 64 # Keycode for right Control. Control_L = 108 # Keycode for left Control. # Keycodes we are listening for. I've left out Right Control # to be able to stop the program. keycodes = [Control_L] # Handle X events. def handle_event(event): # Let us know whether this event is about a Key Release of # one of the keys in which we are interested. if event.type == X.KeyRelease: keycode = event.detail if keycode in keycodes: print "KeyRelease" # Objects needed to call Xlib. display = Display() root = display.screen().root # Tell the X server we want to catch KeyRelease events. root.change_attributes(event_mask = X.KeyReleaseMask) # Grab those keys. for keycode in keycodes: root.grab_key(keycode, X.AnyModifier, 1, X.GrabModeAsync, X.GrabModeAsync) # Event loop. while 1: event = root.display.next_event() handle_event(event) # End of program.
fehmud commented 12 years ago

Gasp! What happened to my program? I checked the syntax of Markdown and here it is again:

    #! /usr/bin/env python

    from Xlib.display import Display
    from Xlib import X

    Control_R  = 64  # Keycode for right Control.
    Control_L  = 108 # Keycode for left Control.
    # Keycodes we are listening for.  I've left out Right Control
    # to be able to stop the program.
    keycodes = [Control_L]

    # Handle X events.
    def handle_event(event):
        # Let us know whether this event is about a Key Release of
        # one of the keys in which we are interested.
        if event.type == X.KeyRelease:
            keycode = event.detail
            if keycode in keycodes:
                print "KeyRelease"

    # Objects needed to call Xlib.
    display = Display()
    root = display.screen().root

    # Tell the X server we want to catch KeyRelease events.
    root.change_attributes(event_mask = X.KeyReleaseMask)

    # Grab those keys.
    for keycode in keycodes:
        root.grab_key(keycode, X.AnyModifier, 1, X.GrabModeAsync, X.GrabModeAsync)

    # Event loop.
    while 1:
        event = root.display.next_event()
        handle_event(event)

    # End of program.