You can feed arbitrary events (keystrokes, mouse clicks, etc.) to the command loop by putting them onto unread-command-events. For example, the following will cause the command loop to execute a break the next time it is run:
(setq unread-command-events (listify-key-sequence "\C-g"))
Note that this only feeds events to the command loop, so it will do ...
You could try:
(defun my-run-fkpiawh ()
(remove-hook 'pre-command-hook #'my-run-fkpiawh)
(run-with-idle-timer 1200 t (lambda ()
After which you can use add functions to first-keypress-in-a-...
I guess a solution of your problem is setting a flag with an idle timer, https://www.gnu.org/software/emacs/manual/html_node/elisp/Idle-Timers.html
and checking/unsetting it with post-self-insert-hook or a similar hook of your choice.
The following works for me:
(defvar *my-idle-flag* nil)
(run-with-idle-timer 900 t (lambda () (setq *my-idle-flag* t)))
Best method seems to be found in eldoc that also displays temporary info in minibuffer:
;; Decide whether now is a good time to display a message.
(defun eldoc-display-message-p ()
;; If this-command is non-nil while running via an idle
;; timer, we're still in the middle of executing a command,
Taken from this answer, you can use global-set-key like this
(global-set-key (kbd "C-`") (kbd "<escape>"))
Which will treat C-` as escape
This does seem to have some problems though if the second combination doesn't execute a function. So if escape is being used like Meta, then it doesn't work correctly. But it seems to work for commands bound to ...
I think you want event-basic-type. E.g. (event-basic-type ?\C-;) returns ?;.
If you want to only stop the control modifier but keep the other modifiers (e.g. the shift modifier), then you can try something like:
(defun my-strip-control (event)
(append (cl-set-difference (event-modifiers event)
Okay, so my first answer has a number of shortcomings as detailed in its comments.
execute-kbd-macro is a built-in function in C source code.
(execute-kbd-macro MACRO &optional COUNT LOOPFUNC)
Execute MACRO as string of editor command characters.
MACRO can also be a vector of keyboard events. If MACRO is a symbol,
its function definition ...
There is a list of functions with the posn prefix to extract that information and more from mouse events. One caveat is that many of them require a start/end event:
(let ((e (read-event)))
(when (mouse-event-p e)
(let ((x-y (posn-x-y (event-start e))))
(message "Mouse event at: %d|%d" (car x-y) (cdr x-y)))))
If a single key/character, just use function single-key-description.
(single-key-description 19) ; => "C-s"
If a list of characters, convert them to a string and use function key-description.
(key-description (string 19 25 20 5 43)) ; => "C-s C-y C-c C-e +"
If a key sequence as a string, use function key-description. (Here I write "^Y" etc when I ...
How can i achieve my goal? Should i take another approach?
IIUC the problem arises from a misuse of nconc. The value of unread-command-events is often nil, in which case nconc will not alter it in-place, as there is no cdr to modify. Instead, you should probably be using push or setq to record the value change of unread-command-events.
invocation of ...
After reading the suggestion from jch to use unread-command-events, I was able to hack together a solution that will do some of the things that I am looking for.
(defun my-simulate-key-event (event &optional N)
"Simulate an arbitrary keypress event.
This function sets the `unread-command-events' variable in order to simulate a
series of key events ...
The answer to “I want to detect (…) event” is usually to use the appropriate hook. The manual has a list of standard hooks. There's no hook that triggers on a line change, so the next thing is to look for a hook that triggers on any motion. There's no hook specifically for that either, to you're down to a hook that runs every command.
Keep track of the ...
Not exactly an answer, but a dirty workaround: give up using tooltip-functions and bind the function directly to mouse-movement, like this:
(defun my-tooltip (event)
(tooltip-show "got mouse movement event")
(set (make-local-variable 'track-mouse) t)
(local-set-key (kbd "<mouse-movement&...
This is expected behavior, but you can circumvent this problem by let-binding executing-kbd-macro to t, which will convince the minibuffer commands to read from unread-command-events rather than from stdin.
my-count-clocks in the following Elisp section defines a function that counts clocks in the current org-mode section. It does not descent into sub-sections. You can easily modify my-count-clocks to fit your special needs, e.g., work recursive on sub-sections.
That function has a predicate function as argument. The predicate gets a timestamp as argument and ...
Release of a keyboard key is not an event that is detected by Emacs. (But release of a mouse button is an event seen by Emacs.)
Maybe change from reading and acting on a single character to acting on two keys, separately: Act on the first key by doing what you describe first: "perform the replacement but "pause" the loop until" the second key is pressed. ...
For y-or-n-p, you could check the value of input-method-use-echo-area. It is turned on by read-key-sequence, which is indirectly used by y-or-n-p – and quite likely by various other commands you'd like to treat the same way.
Detecting an active read-event seems to be harder. Perhaps it's preferable to call it via a wrapper which rebinds some variable to let ...
If you have to stay in emacs, then the two options I've tried are:
(process-send-string "my-vm-1" "command to vm")
where I'd change my-vm-1 to my-vm-2 and so on in a macro. The other option I use now is to run gnu-parallel via M-x !.
A more recent solution for VMs to use their own mgmt interface to send commands to to multiple instances. This may turn out ...
Based on phils' comment, this is what I needed to do to make it work:
(setq doubletap-flag nil)
(defun doubletap (doubletap-key1 doubletap-key2 doubletap-wait doubletap-function)
(setq doubletap-flag 't)
(let ((doubletap-event (read-event nil nil doubletap-wait)))
(if (equal doubletap-event doubletap-key2)
You need to manually move the point in your function like this:
(defun mouse-test (event)
"Move the point to the clicked position and message the thing at point."
(let ((es (event-start event)))
(select-window (posn-window es))
(goto-char (posn-point es))
(message (thing-at-point 'word))))
Do C-hfinteractive to ...