help-gnu-emacs
[Top][All Lists]
Advanced

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

how to genererate 'C-x @ c' from within a custom keymap


From: Andrés Ramírez
Subject: how to genererate 'C-x @ c' from within a custom keymap
Date: Thu, 21 Jul 2022 18:51:56 +0000

Hi. Sometimes I should use a bluetooth keyboard without the Right
control key (cos it is absent on this model).

So. When I need to press the Right Control key for doing C-a or C-e.

I end doing 'C-x @ c'. So far so good.

Pressing C-x is very difficult. So that should be fixed.

Trying to fix it.  Ended with this:
--8<---------------cut here---------------start------------->8---
(global-set-key (kbd "M-h") (lambda () (interactive) (emacsstacko/call-keymap 
ik-launch-keymap "*Your-key*?:")))
--8<---------------cut here---------------end--------------->8---

JIC. I am not the author of this function.
,---- [  ]
| (defun emacsstacko/call-keymap (map &optional prompt)
|   "Read a key sequence and call the command it's bound to in MAP."
|   ;; Note: MAP must be a symbol so we can trick `describe-bindings' into 
giving
|   ;; us a nice help text.
|   (let* ((overriding-local-map `(keymap (,map . ,map)))
|                                         ;(help-form `(describe-bindings 
,(vector map))) ; conflicts with C-h
|          (key (read-key-sequence prompt))
|          (cmd (lookup-key map key t)))
|     (if (functionp cmd) (call-interactively cmd)
|       (user-error "%s is undefined" key))))
|
`----

And I also have this:
--8<---------------cut here---------------start------------->8---
(defvar ik-launch-keymap (make-sparse-keymap))
;;; below works. But needs xdotool
(define-key ik-launch-keymap "c" (lambda () (interactive) 
(shell-command-to-string "xdotool key ctrl+x; xdotool type @c")))
(define-key ik-launch-keymap "o" 'other-window)
(define-key ik-launch-keymap "x" (lambda () (interactive) (run-at-time nil nil 
#'call-interactively 'execute-extended-command)))
--8<---------------cut here---------------end--------------->8---

I want to replace the use of xdotool.
How I should I emulate the pressing of 'C-x @ c'. From within this
custom keymap?.

I have tried a couple of things without success.
(define-key ik-launch-keymap "c" 'event-apply-control-modifier)

And Also I have wrapped 'event-apply-control-modifier within an
interactive function.

Best Regards
ps: btw this one works. But very difficult to press.
(define-key key-translation-map (kbd "M-i") 'event-apply-control-modifier)



reply via email to

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