[Tutor] Fwd: Re: call key on_press event multiple times when key is held down
Alan Gauld
alan.gauld at yahoo.co.uk
Tue Jul 4 07:00:38 EDT 2017
Forwarding to Tutor list
Please always use reply-All or reply-List to respond to tutor posts.
-------- Forwarded Message --------
> Den 4. jul. 2017 kl. 11.35 skrev Alan Gauld via Tutor <tutor at python.org>:
>
> On 04/07/17 09:50, Carlton Banks wrote:
>> I am trying to record from my microphone while i press down a button,
>
> First question is which OS?
> That makes a big difference in this kind of scenario.
I am currently testing it on OS X, but should also be working on a ubuntu machine.
>> the library I am using is not able to detect on hold event.
>
> There isn't really any concept of a hold event, you usually
> have to detect repeated press events. However I don;t know
> the library you are using, I normally just use the standard
> library for such things, or build a simple GUI…
Standard library being?..
>
>> It only detect on press, which happens once,
>
> That's unusual, usually you get a repeated stream of
> press events when you hold a key down. But it does
> depend on the OS and environment. Your library may
> indeed just be detecting the initial key down and
> be waiting for the key up event.
Hmm.. interesting but again it is currently being tested on OSX,
as it was the only machine available atm.
>
>> So does any of you know any libraries that monitor> state of the keyboard,
>
> There are several but it depends on your OS.
> In the standard library
> Unix variants can use curses.
> Windows users have msvcrt.
>
> And there are several 3rd party libraries that try
> to do in a platform independent way - I'm guessing
> the one you are using is one such.
>
> Another way to tackle it is to switch your code so
> it works with a toggle. Set the toggle to on in
> the on_press handler. Set it to off in the
> on_release handler
>
> Then trigger a timer loop that runs for as long
> as the toggle is set. This is probably easiest
> done within a GUI.
>
Interesting solution, but still find a bit "dirty hackish”
to involve a timer in this.. I guess it just would be neat if
it just worked as i thought it to be. But i guess i have to look into curses.
More information about the Tutor
mailing list