How do you make a toggle key using Autokey?
Clash Royale CLAN TAG#URR8PPP
I want to use Autokey to toggle the e key on and off in a program called "xyz". So if I press e, the program thinks I'm holding down e. I press e again, it thinks I released it. How do you do this please?
Or is there some other program that can do this?
bonus question: how do you do this with any Ubuntu program, such as fvwm2, xorg, xmodmap, xkb, xrdb, any way at all?
scripting x11 keyboard-shortcuts
add a comment |
I want to use Autokey to toggle the e key on and off in a program called "xyz". So if I press e, the program thinks I'm holding down e. I press e again, it thinks I released it. How do you do this please?
Or is there some other program that can do this?
bonus question: how do you do this with any Ubuntu program, such as fvwm2, xorg, xmodmap, xkb, xrdb, any way at all?
scripting x11 keyboard-shortcuts
add a comment |
I want to use Autokey to toggle the e key on and off in a program called "xyz". So if I press e, the program thinks I'm holding down e. I press e again, it thinks I released it. How do you do this please?
Or is there some other program that can do this?
bonus question: how do you do this with any Ubuntu program, such as fvwm2, xorg, xmodmap, xkb, xrdb, any way at all?
scripting x11 keyboard-shortcuts
I want to use Autokey to toggle the e key on and off in a program called "xyz". So if I press e, the program thinks I'm holding down e. I press e again, it thinks I released it. How do you do this please?
Or is there some other program that can do this?
bonus question: how do you do this with any Ubuntu program, such as fvwm2, xorg, xmodmap, xkb, xrdb, any way at all?
scripting x11 keyboard-shortcuts
scripting x11 keyboard-shortcuts
edited Apr 26 '15 at 20:43
Gilles
543k12811011618
543k12811011618
asked Apr 26 '15 at 1:27
user111973user111973
113
113
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I'm not familiar with autokey, but this looks doable. Use Keyboard.press_key
to send a key press event and Keyboard.release_key
to send a key release event. To remember which one to send, you can use Store.set_value
and Store.get_value
.
Alternatively, you can use xdotool to inject input events into a window and xprop
to attach data to a window. Run the following shell command (untested) to send alternate press/release events to the active window.
#!/bin/sh
window_id=$(xdotool getactivewindow)
case $(xprop -id "$window_id" -f key_e_is_down 32c -notype key_e_is_down) in
*1) key_command=keydown; new_state=0;;
*) key_command=keyup; new_state=1;;
esac
xdotool "$key_command" "e"
xprop -id "$window_id" -f key_e_is_down 32c -set key_e_is_down "$new_state"
If you want to bind this action to a key, but to have the key active only in one window, I'm not sure if Autokey can help you. The easiest way to do that is from the window manager, but most window managers can't do it. I use sawfish as my window manager, which can do this without any external tool.
(define (toggle-e w)
(interactive "%W")
(let ((down (window-get w 'key-e-is-down)))
(synthesize-event (if down "Release+e" "e") w)
(window-put w 'key-e-is-down (not down))))
(define xyz-window-map (make-keymap))
(bind-keys xyz-window-map "e" toggle-e)
(add-window-matcher 'WM_CLASS "^Xyz/" `((keymap . ,xyz-window-map)))
Thanks for an interesting answer Gilles. The case line in the shell script i changed to: 'xprop -id "$window_id" -f key_e_is_down 32c -notype|grep key_e_is_down|cut -f3' which seems a bit excessive, but xprop doesn't seem to have a get property function. xdotool is interesting but it seems to only send characters until some other keyboard event comes along, which isn't enough. It would have to keep sending until toggled. Tried doing it using fvwm2 but that didn't work out either. Thanks again.
– user111973
Apr 27 '15 at 5:27
@user111973 To get a property usingxprop
, add the name of the property at the end. I somehow removed that when I was editing the script, I've added it back. The xdotool and sawfish snippets I wrote only send a key press event, and later a key release event; they don't keep sending key press events to simulate keyboard repeat, because that wasn't a requirement in your question. Doing that would be possible, but more work, I think you'd need to keep a program running to do just that. Do you need the key to be sent even while xyz isn't the active window?
– Gilles
Apr 27 '15 at 9:31
I thought sending a keydown without a keyrelease would make the program think i was holding it down, but apparently not. Also the program might be rejecting synthetic events, so i might be forced into a hardware solution. Thanks again.
– user111973
Apr 27 '15 at 21:40
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f198650%2fhow-do-you-make-a-toggle-key-using-autokey%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not familiar with autokey, but this looks doable. Use Keyboard.press_key
to send a key press event and Keyboard.release_key
to send a key release event. To remember which one to send, you can use Store.set_value
and Store.get_value
.
Alternatively, you can use xdotool to inject input events into a window and xprop
to attach data to a window. Run the following shell command (untested) to send alternate press/release events to the active window.
#!/bin/sh
window_id=$(xdotool getactivewindow)
case $(xprop -id "$window_id" -f key_e_is_down 32c -notype key_e_is_down) in
*1) key_command=keydown; new_state=0;;
*) key_command=keyup; new_state=1;;
esac
xdotool "$key_command" "e"
xprop -id "$window_id" -f key_e_is_down 32c -set key_e_is_down "$new_state"
If you want to bind this action to a key, but to have the key active only in one window, I'm not sure if Autokey can help you. The easiest way to do that is from the window manager, but most window managers can't do it. I use sawfish as my window manager, which can do this without any external tool.
(define (toggle-e w)
(interactive "%W")
(let ((down (window-get w 'key-e-is-down)))
(synthesize-event (if down "Release+e" "e") w)
(window-put w 'key-e-is-down (not down))))
(define xyz-window-map (make-keymap))
(bind-keys xyz-window-map "e" toggle-e)
(add-window-matcher 'WM_CLASS "^Xyz/" `((keymap . ,xyz-window-map)))
Thanks for an interesting answer Gilles. The case line in the shell script i changed to: 'xprop -id "$window_id" -f key_e_is_down 32c -notype|grep key_e_is_down|cut -f3' which seems a bit excessive, but xprop doesn't seem to have a get property function. xdotool is interesting but it seems to only send characters until some other keyboard event comes along, which isn't enough. It would have to keep sending until toggled. Tried doing it using fvwm2 but that didn't work out either. Thanks again.
– user111973
Apr 27 '15 at 5:27
@user111973 To get a property usingxprop
, add the name of the property at the end. I somehow removed that when I was editing the script, I've added it back. The xdotool and sawfish snippets I wrote only send a key press event, and later a key release event; they don't keep sending key press events to simulate keyboard repeat, because that wasn't a requirement in your question. Doing that would be possible, but more work, I think you'd need to keep a program running to do just that. Do you need the key to be sent even while xyz isn't the active window?
– Gilles
Apr 27 '15 at 9:31
I thought sending a keydown without a keyrelease would make the program think i was holding it down, but apparently not. Also the program might be rejecting synthetic events, so i might be forced into a hardware solution. Thanks again.
– user111973
Apr 27 '15 at 21:40
add a comment |
I'm not familiar with autokey, but this looks doable. Use Keyboard.press_key
to send a key press event and Keyboard.release_key
to send a key release event. To remember which one to send, you can use Store.set_value
and Store.get_value
.
Alternatively, you can use xdotool to inject input events into a window and xprop
to attach data to a window. Run the following shell command (untested) to send alternate press/release events to the active window.
#!/bin/sh
window_id=$(xdotool getactivewindow)
case $(xprop -id "$window_id" -f key_e_is_down 32c -notype key_e_is_down) in
*1) key_command=keydown; new_state=0;;
*) key_command=keyup; new_state=1;;
esac
xdotool "$key_command" "e"
xprop -id "$window_id" -f key_e_is_down 32c -set key_e_is_down "$new_state"
If you want to bind this action to a key, but to have the key active only in one window, I'm not sure if Autokey can help you. The easiest way to do that is from the window manager, but most window managers can't do it. I use sawfish as my window manager, which can do this without any external tool.
(define (toggle-e w)
(interactive "%W")
(let ((down (window-get w 'key-e-is-down)))
(synthesize-event (if down "Release+e" "e") w)
(window-put w 'key-e-is-down (not down))))
(define xyz-window-map (make-keymap))
(bind-keys xyz-window-map "e" toggle-e)
(add-window-matcher 'WM_CLASS "^Xyz/" `((keymap . ,xyz-window-map)))
Thanks for an interesting answer Gilles. The case line in the shell script i changed to: 'xprop -id "$window_id" -f key_e_is_down 32c -notype|grep key_e_is_down|cut -f3' which seems a bit excessive, but xprop doesn't seem to have a get property function. xdotool is interesting but it seems to only send characters until some other keyboard event comes along, which isn't enough. It would have to keep sending until toggled. Tried doing it using fvwm2 but that didn't work out either. Thanks again.
– user111973
Apr 27 '15 at 5:27
@user111973 To get a property usingxprop
, add the name of the property at the end. I somehow removed that when I was editing the script, I've added it back. The xdotool and sawfish snippets I wrote only send a key press event, and later a key release event; they don't keep sending key press events to simulate keyboard repeat, because that wasn't a requirement in your question. Doing that would be possible, but more work, I think you'd need to keep a program running to do just that. Do you need the key to be sent even while xyz isn't the active window?
– Gilles
Apr 27 '15 at 9:31
I thought sending a keydown without a keyrelease would make the program think i was holding it down, but apparently not. Also the program might be rejecting synthetic events, so i might be forced into a hardware solution. Thanks again.
– user111973
Apr 27 '15 at 21:40
add a comment |
I'm not familiar with autokey, but this looks doable. Use Keyboard.press_key
to send a key press event and Keyboard.release_key
to send a key release event. To remember which one to send, you can use Store.set_value
and Store.get_value
.
Alternatively, you can use xdotool to inject input events into a window and xprop
to attach data to a window. Run the following shell command (untested) to send alternate press/release events to the active window.
#!/bin/sh
window_id=$(xdotool getactivewindow)
case $(xprop -id "$window_id" -f key_e_is_down 32c -notype key_e_is_down) in
*1) key_command=keydown; new_state=0;;
*) key_command=keyup; new_state=1;;
esac
xdotool "$key_command" "e"
xprop -id "$window_id" -f key_e_is_down 32c -set key_e_is_down "$new_state"
If you want to bind this action to a key, but to have the key active only in one window, I'm not sure if Autokey can help you. The easiest way to do that is from the window manager, but most window managers can't do it. I use sawfish as my window manager, which can do this without any external tool.
(define (toggle-e w)
(interactive "%W")
(let ((down (window-get w 'key-e-is-down)))
(synthesize-event (if down "Release+e" "e") w)
(window-put w 'key-e-is-down (not down))))
(define xyz-window-map (make-keymap))
(bind-keys xyz-window-map "e" toggle-e)
(add-window-matcher 'WM_CLASS "^Xyz/" `((keymap . ,xyz-window-map)))
I'm not familiar with autokey, but this looks doable. Use Keyboard.press_key
to send a key press event and Keyboard.release_key
to send a key release event. To remember which one to send, you can use Store.set_value
and Store.get_value
.
Alternatively, you can use xdotool to inject input events into a window and xprop
to attach data to a window. Run the following shell command (untested) to send alternate press/release events to the active window.
#!/bin/sh
window_id=$(xdotool getactivewindow)
case $(xprop -id "$window_id" -f key_e_is_down 32c -notype key_e_is_down) in
*1) key_command=keydown; new_state=0;;
*) key_command=keyup; new_state=1;;
esac
xdotool "$key_command" "e"
xprop -id "$window_id" -f key_e_is_down 32c -set key_e_is_down "$new_state"
If you want to bind this action to a key, but to have the key active only in one window, I'm not sure if Autokey can help you. The easiest way to do that is from the window manager, but most window managers can't do it. I use sawfish as my window manager, which can do this without any external tool.
(define (toggle-e w)
(interactive "%W")
(let ((down (window-get w 'key-e-is-down)))
(synthesize-event (if down "Release+e" "e") w)
(window-put w 'key-e-is-down (not down))))
(define xyz-window-map (make-keymap))
(bind-keys xyz-window-map "e" toggle-e)
(add-window-matcher 'WM_CLASS "^Xyz/" `((keymap . ,xyz-window-map)))
edited Apr 27 '15 at 9:31
answered Apr 26 '15 at 20:41
GillesGilles
543k12811011618
543k12811011618
Thanks for an interesting answer Gilles. The case line in the shell script i changed to: 'xprop -id "$window_id" -f key_e_is_down 32c -notype|grep key_e_is_down|cut -f3' which seems a bit excessive, but xprop doesn't seem to have a get property function. xdotool is interesting but it seems to only send characters until some other keyboard event comes along, which isn't enough. It would have to keep sending until toggled. Tried doing it using fvwm2 but that didn't work out either. Thanks again.
– user111973
Apr 27 '15 at 5:27
@user111973 To get a property usingxprop
, add the name of the property at the end. I somehow removed that when I was editing the script, I've added it back. The xdotool and sawfish snippets I wrote only send a key press event, and later a key release event; they don't keep sending key press events to simulate keyboard repeat, because that wasn't a requirement in your question. Doing that would be possible, but more work, I think you'd need to keep a program running to do just that. Do you need the key to be sent even while xyz isn't the active window?
– Gilles
Apr 27 '15 at 9:31
I thought sending a keydown without a keyrelease would make the program think i was holding it down, but apparently not. Also the program might be rejecting synthetic events, so i might be forced into a hardware solution. Thanks again.
– user111973
Apr 27 '15 at 21:40
add a comment |
Thanks for an interesting answer Gilles. The case line in the shell script i changed to: 'xprop -id "$window_id" -f key_e_is_down 32c -notype|grep key_e_is_down|cut -f3' which seems a bit excessive, but xprop doesn't seem to have a get property function. xdotool is interesting but it seems to only send characters until some other keyboard event comes along, which isn't enough. It would have to keep sending until toggled. Tried doing it using fvwm2 but that didn't work out either. Thanks again.
– user111973
Apr 27 '15 at 5:27
@user111973 To get a property usingxprop
, add the name of the property at the end. I somehow removed that when I was editing the script, I've added it back. The xdotool and sawfish snippets I wrote only send a key press event, and later a key release event; they don't keep sending key press events to simulate keyboard repeat, because that wasn't a requirement in your question. Doing that would be possible, but more work, I think you'd need to keep a program running to do just that. Do you need the key to be sent even while xyz isn't the active window?
– Gilles
Apr 27 '15 at 9:31
I thought sending a keydown without a keyrelease would make the program think i was holding it down, but apparently not. Also the program might be rejecting synthetic events, so i might be forced into a hardware solution. Thanks again.
– user111973
Apr 27 '15 at 21:40
Thanks for an interesting answer Gilles. The case line in the shell script i changed to: 'xprop -id "$window_id" -f key_e_is_down 32c -notype|grep key_e_is_down|cut -f3' which seems a bit excessive, but xprop doesn't seem to have a get property function. xdotool is interesting but it seems to only send characters until some other keyboard event comes along, which isn't enough. It would have to keep sending until toggled. Tried doing it using fvwm2 but that didn't work out either. Thanks again.
– user111973
Apr 27 '15 at 5:27
Thanks for an interesting answer Gilles. The case line in the shell script i changed to: 'xprop -id "$window_id" -f key_e_is_down 32c -notype|grep key_e_is_down|cut -f3' which seems a bit excessive, but xprop doesn't seem to have a get property function. xdotool is interesting but it seems to only send characters until some other keyboard event comes along, which isn't enough. It would have to keep sending until toggled. Tried doing it using fvwm2 but that didn't work out either. Thanks again.
– user111973
Apr 27 '15 at 5:27
@user111973 To get a property using
xprop
, add the name of the property at the end. I somehow removed that when I was editing the script, I've added it back. The xdotool and sawfish snippets I wrote only send a key press event, and later a key release event; they don't keep sending key press events to simulate keyboard repeat, because that wasn't a requirement in your question. Doing that would be possible, but more work, I think you'd need to keep a program running to do just that. Do you need the key to be sent even while xyz isn't the active window?– Gilles
Apr 27 '15 at 9:31
@user111973 To get a property using
xprop
, add the name of the property at the end. I somehow removed that when I was editing the script, I've added it back. The xdotool and sawfish snippets I wrote only send a key press event, and later a key release event; they don't keep sending key press events to simulate keyboard repeat, because that wasn't a requirement in your question. Doing that would be possible, but more work, I think you'd need to keep a program running to do just that. Do you need the key to be sent even while xyz isn't the active window?– Gilles
Apr 27 '15 at 9:31
I thought sending a keydown without a keyrelease would make the program think i was holding it down, but apparently not. Also the program might be rejecting synthetic events, so i might be forced into a hardware solution. Thanks again.
– user111973
Apr 27 '15 at 21:40
I thought sending a keydown without a keyrelease would make the program think i was holding it down, but apparently not. Also the program might be rejecting synthetic events, so i might be forced into a hardware solution. Thanks again.
– user111973
Apr 27 '15 at 21:40
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f198650%2fhow-do-you-make-a-toggle-key-using-autokey%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown