emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to know if a key is pressed without getting it?


From: Vinicius Jose Latorre
Subject: Re: How to know if a key is pressed without getting it?
Date: Sun, 26 Sep 2010 21:29:13 -0300
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.13) Gecko/20100914 SeaMonkey/2.0.8


I defined the following function using input-pending-p:
(defun test-input ()
   (read-char "char: ")
   (while (input-pending-p)
     (insert (format "{%S}" unread-command-events)))
   (message "{%S} END" last-input-char))
Execute the function above via: M-: (test-input) RET Then hold space key. The only message returned is "{32} END" followed by all spaces that
I pressed (except the first one).
This probably depends on how quickly the read-char returns and the
input-pending-p gets run, but it seems reasonable to expect it to be run
in (much) less time than your repeat rate, so when the input-pending-p
is run, there is indeed no input pending yet.

Ok, you're right, I redefined test-input:

(defun test-input ()
  (read-char "char: ")
  (sleep-for 0.3)
  (while (input-pending-p)
    (insert (format "{%S}" unread-command-events)))
  (message "{%S} END" last-input-char))

Now, input-pending-p is working.

So, input-pending-p will not work to fix the problem, because the event (key being holded) happens after the detection (input-pending-p).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]