* Inhibit more keyboard event during execution of function
@ 2009-12-28 21:49 Mathias Dahl
2009-12-29 6:51 ` Kevin Rodgers
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Mathias Dahl @ 2009-12-28 21:49 UTC (permalink / raw)
To: help-gnu-emacs
I have made a small game for my kid that lets him press a key and that
will play a sound and display an image. It is implemented as a major
mode with a keymap where each key is defined using `define-key' and
bound to a special play command with a string of what to play (say,
"cow"). Now, it works for me, but when I tested this on my son today he
kept the key pressed way longer than I do, with the effect that the key
repeats, playing the sound many times. Quite annoying. Is there a way to
get around this? I have been thinking of having some timing built in so
that I will not play again unless a certain time has passed.
Also, even though I tell Emacs to draw the image first (using
`insert-image-file'), it is not displayed until the sound has stopped
playing (I use `play-sound-file'). Any way around this?
Thanks!
/Mathias
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Inhibit more keyboard event during execution of function
2009-12-28 21:49 Inhibit more keyboard event during execution of function Mathias Dahl
@ 2009-12-29 6:51 ` Kevin Rodgers
[not found] ` <mailman.367.1262069524.18930.help-gnu-emacs@gnu.org>
` (2 subsequent siblings)
3 siblings, 0 replies; 12+ messages in thread
From: Kevin Rodgers @ 2009-12-29 6:51 UTC (permalink / raw)
To: help-gnu-emacs
Mathias Dahl wrote:
> I have made a small game for my kid that lets him press a key and that
> will play a sound and display an image. It is implemented as a major
> mode with a keymap where each key is defined using `define-key' and
> bound to a special play command with a string of what to play (say,
> "cow"). Now, it works for me, but when I tested this on my son today he
> kept the key pressed way longer than I do, with the effect that the key
> repeats, playing the sound many times. Quite annoying. Is there a way to
> get around this? I have been thinking of having some timing built in so
> that I will not play again unless a certain time has passed.
>
> Also, even though I tell Emacs to draw the image first (using
> `insert-image-file'), it is not displayed until the sound has stopped
> playing (I use `play-sound-file'). Any way around this?
I don't know if this will work, but you could try let-binding
unread-command-events to nil while the sound is being played.
The idea is that any input events would be added to the queue,
but when the sound is done the queued events would be discarded
and the command loop wouldn't see them.
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Inhibit more keyboard event during execution of function
[not found] ` <mailman.367.1262069524.18930.help-gnu-emacs@gnu.org>
@ 2009-12-29 20:03 ` Mathias Dahl
2009-12-29 20:53 ` Lennart Borgman
[not found] ` <mailman.388.1262120023.18930.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 12+ messages in thread
From: Mathias Dahl @ 2009-12-29 20:03 UTC (permalink / raw)
To: help-gnu-emacs
> I don't know if this will work, but you could try let-binding
> unread-command-events to nil while the sound is being played.
> The idea is that any input events would be added to the queue,
> but when the sound is done the queued events would be discarded
> and the command loop wouldn't see them.
Thanks! It sounded like a good idea but it did not work. This is what
I did:
(defun esb-play (thing)
"Play sound and display image for THING."
(let ((unread-command-events nil))
(esb-display-image (concat esb-data-dir thing ".jpg"))
(play-sound-file ...
...
If I keep a key pressed or type it repeatedly it will still
"record" (queue?)
what is pressed during play.
Any other ideas?
/Mathias
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Inhibit more keyboard event during execution of function
2009-12-29 20:03 ` Mathias Dahl
@ 2009-12-29 20:53 ` Lennart Borgman
[not found] ` <mailman.388.1262120023.18930.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 12+ messages in thread
From: Lennart Borgman @ 2009-12-29 20:53 UTC (permalink / raw)
To: Mathias Dahl; +Cc: help-gnu-emacs
On Tue, Dec 29, 2009 at 9:03 PM, Mathias Dahl <mathias.dahl@gmail.com> wrote:
>
> If I keep a key pressed or type it repeatedly it will still
> "record" (queue?)
> what is pressed during play.
>
> Any other ideas?
Put a keymap in emulation-mode-map-alist with `ignore' as default key
during the play?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Inhibit more keyboard event during execution of function
2009-12-28 21:49 Inhibit more keyboard event during execution of function Mathias Dahl
2009-12-29 6:51 ` Kevin Rodgers
[not found] ` <mailman.367.1262069524.18930.help-gnu-emacs@gnu.org>
@ 2009-12-29 22:11 ` Ilya Zakharevich
2009-12-29 22:38 ` Mathias Dahl
2009-12-29 22:56 ` Mathias Dahl
3 siblings, 1 reply; 12+ messages in thread
From: Ilya Zakharevich @ 2009-12-29 22:11 UTC (permalink / raw)
To: help-gnu-emacs
On 2009-12-28, Mathias Dahl <mathias.dahl@gmail.com> wrote:
> I have made a small game for my kid that lets him press a key and that
> will play a sound and display an image. It is implemented as a major
> mode with a keymap where each key is defined using `define-key' and
> bound to a special play command with a string of what to play (say,
> "cow"). Now, it works for me, but when I tested this on my son today he
> kept the key pressed way longer than I do, with the effect that the key
> repeats, playing the sound many times. Quite annoying. Is there a way to
> get around this? I have been thinking of having some timing built in so
> that I will not play again unless a certain time has passed.
>
> Also, even though I tell Emacs to draw the image first (using
> `insert-image-file'), it is not displayed until the sound has stopped
> playing (I use `play-sound-file'). Any way around this?
If you sound is played syncroneously, just introduce a global
variable, set it on during sound play, and do sound play conditionally
- only if the variable is not set.
If the play is async - may be much harder...
Hope this helps,
Ilya
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Inhibit more keyboard event during execution of function
2009-12-29 22:11 ` Ilya Zakharevich
@ 2009-12-29 22:38 ` Mathias Dahl
0 siblings, 0 replies; 12+ messages in thread
From: Mathias Dahl @ 2009-12-29 22:38 UTC (permalink / raw)
To: help-gnu-emacs
> If you sound is played syncroneously, just introduce a global
> variable, set it on during sound play, and do sound play conditionally
> - only if the variable is not set.
The problem is not that the same sound is played at the same time, the
problem is that during the play the system accepts more keyboard
events and adds them to the queue, later playing sound when the key
binding is executed. If I use a global variable it will work in the
sense that no other/new sound will be played during play, but when the
playing is done and I set the global variable to false again the next
keyboard event will fire. Right?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Inhibit more keyboard event during execution of function
[not found] ` <mailman.388.1262120023.18930.help-gnu-emacs@gnu.org>
@ 2009-12-29 22:40 ` Mathias Dahl
2009-12-29 23:52 ` Lennart Borgman
0 siblings, 1 reply; 12+ messages in thread
From: Mathias Dahl @ 2009-12-29 22:40 UTC (permalink / raw)
To: help-gnu-emacs
> Put a keymap in emulation-mode-map-alist with `ignore' as default key
> during the play?
You don't happen to have a recipe for that, do you? :) I tested it
briefly but either I did not do it correctly or the approach does not
work.
Can't I just temporarily rebind the key that played the current
"thing" and rebind it again afterwards in my own keymap?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Inhibit more keyboard event during execution of function
2009-12-28 21:49 Inhibit more keyboard event during execution of function Mathias Dahl
` (2 preceding siblings ...)
2009-12-29 22:11 ` Ilya Zakharevich
@ 2009-12-29 22:56 ` Mathias Dahl
2009-12-29 23:00 ` Mathias Dahl
3 siblings, 1 reply; 12+ messages in thread
From: Mathias Dahl @ 2009-12-29 22:56 UTC (permalink / raw)
To: help-gnu-emacs
On Dec 28, 10:49 pm, Mathias Dahl <mathias.d...@gmail.com> wrote:
> I have made a small game for my kid that lets him press a key and that
> will play a sound and display an image. It is implemented as a major
> mode with a keymap where each key is defined using `define-key' and
> bound to a special play command with a string of what to play (say,
> "cow"). Now, it works for me, but when I tested this on my son today he
> kept the key pressed way longer than I do, with the effect that the key
> repeats, playing the sound many times. Quite annoying. Is there a way to
> get around this? I have been thinking of having some timing built in so
> that I will not play again unless a certain time has passed.
>
> Also, even though I tell Emacs to draw the image first (using
> `insert-image-file'), it is not displayed until the sound has stopped
> playing (I use `play-sound-file'). Any way around this?
I solved the first problem by saving the time when the sound is
playing and then refusing to play a sound again until at least a
second has passed. Feels ugly but seems to work okay.
Any takers on the second problem? Can I force redisplay of the image
in the display buffer before the sound is played?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Inhibit more keyboard event during execution of function
2009-12-29 22:56 ` Mathias Dahl
@ 2009-12-29 23:00 ` Mathias Dahl
2009-12-30 9:52 ` Andreas Politz
[not found] ` <mailman.421.1262166805.18930.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 12+ messages in thread
From: Mathias Dahl @ 2009-12-29 23:00 UTC (permalink / raw)
To: help-gnu-emacs
> Any takers on the second problem? Can I force redisplay of the image
> in the display buffer before the sound is played?
Hehe, turns out there is a function called `redisplay' and when I put
that between the display of the image and the playing of the sound I
get what I want. Yay!
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Inhibit more keyboard event during execution of function
2009-12-29 22:40 ` Mathias Dahl
@ 2009-12-29 23:52 ` Lennart Borgman
0 siblings, 0 replies; 12+ messages in thread
From: Lennart Borgman @ 2009-12-29 23:52 UTC (permalink / raw)
To: Mathias Dahl; +Cc: help-gnu-emacs
On Tue, Dec 29, 2009 at 11:40 PM, Mathias Dahl <mathias.dahl@gmail.com> wrote:
>> Put a keymap in emulation-mode-map-alist with `ignore' as default key
>> during the play?
>
> You don't happen to have a recipe for that, do you? :) I tested it
> briefly but either I did not do it correctly or the approach does not
> work.
Look in tabkey2.el
> Can't I just temporarily rebind the key that played the current
> "thing" and rebind it again afterwards in my own keymap?
Yes, of course. The way above is perhaps more general if you want to redo it.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Inhibit more keyboard event during execution of function
2009-12-29 23:00 ` Mathias Dahl
@ 2009-12-30 9:52 ` Andreas Politz
[not found] ` <mailman.421.1262166805.18930.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 12+ messages in thread
From: Andreas Politz @ 2009-12-30 9:52 UTC (permalink / raw)
To: help-gnu-emacs
Mathias Dahl <mathias.dahl@gmail.com> writes:
>> Any takers on the second problem? Can I force redisplay of the image
>> in the display buffer before the sound is played?
>
> Hehe, turns out there is a function called `redisplay' and when I put
> that between the display of the image and the playing of the sound I
> get what I want. Yay!
There is also a function `discard-input', which might be helpful.
-ap
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Inhibit more keyboard event during execution of function
[not found] ` <mailman.421.1262166805.18930.help-gnu-emacs@gnu.org>
@ 2009-12-31 7:51 ` Mathias Dahl
0 siblings, 0 replies; 12+ messages in thread
From: Mathias Dahl @ 2009-12-31 7:51 UTC (permalink / raw)
To: help-gnu-emacs
> There is also a function `discard-input', which might be helpful.
Aha! First I did not think it helped, I had the call to it before I
play the sound. When I moved it to afterwards it works as I want it
to. I guess it makes sense: *after* playing I want to get rid of any
input events I got in the meantime. Now I can get rid of the ugly
measure-time-hack.
Many thanks, Andreas!
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2009-12-31 7:51 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-28 21:49 Inhibit more keyboard event during execution of function Mathias Dahl
2009-12-29 6:51 ` Kevin Rodgers
[not found] ` <mailman.367.1262069524.18930.help-gnu-emacs@gnu.org>
2009-12-29 20:03 ` Mathias Dahl
2009-12-29 20:53 ` Lennart Borgman
[not found] ` <mailman.388.1262120023.18930.help-gnu-emacs@gnu.org>
2009-12-29 22:40 ` Mathias Dahl
2009-12-29 23:52 ` Lennart Borgman
2009-12-29 22:11 ` Ilya Zakharevich
2009-12-29 22:38 ` Mathias Dahl
2009-12-29 22:56 ` Mathias Dahl
2009-12-29 23:00 ` Mathias Dahl
2009-12-30 9:52 ` Andreas Politz
[not found] ` <mailman.421.1262166805.18930.help-gnu-emacs@gnu.org>
2009-12-31 7:51 ` Mathias Dahl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).