Application-specific key combination remapping? Unicorn Meta Zoo #1: Why another podcast? ...
What is the best way to deal with NPC-NPC combat?
How to use @AuraEnabled base class method in Lightning Component?
How can I make a line end at the edge of an irregular shape?
A Paper Record is What I Hamper
Does Feeblemind produce an ongoing magical effect that can be dispelled?
With indentation set to `0em`, when using a line break, there is still an indentation of a size of a space
Raising a bilingual kid. When should we introduce the majority language?
Could Neutrino technically as side-effect, incentivize centralization of the bitcoin network?
Is a 5 watt UHF/VHF handheld considered QRP?
What do you call the part of a novel that is not dialog?
France's Public Holidays' Puzzle
"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"
What ability score does a Hexblade's Pact Weapon use for attack and damage when wielded by another character?
Has a Nobel Peace laureate ever been accused of war crimes?
How would I use different systems of magic when they are capable of the same effects?
Arriving in Atlanta after US Preclearance in Dublin. Will I go through TSA security in Atlanta to transfer to a connecting flight?
Is there any hidden 'W' sound after 'comment' in : Comment est-elle?
c++ diamond problem - How to call base method only once
What is this word supposed to be?
"Rubric" as meaning "signature" or "personal mark" -- is this accepted usage?
Book with legacy programming code on a space ship that the main character hacks to escape
My bank got bought out, am I now going to have to start filing tax returns in a different state?
What is /etc/mtab in Linux?
Israeli soda type drink
Application-specific key combination remapping?
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraHow do I bind right click to a keyboard shortcut?How do you assign commands to keys in Terminal?Emacs-like keybindings globallyRemapping keyboard shortcuts (copy, paste etc) to Alt key instead of CtrlHow to bind a key such that it toggles between one particular application and the current application?How to customize hotkeyschange or disable modifier key (alt) which activates the application menubar?Disable Alt-Key menu combinationsHow to type key combinations instead of pressing them?How to manipulate the keypress that applications recieve?Alt key randomly behaves as ctrl when switching workspaces
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I'm aware of a number of ways of remapping key combinations in Ubuntu on a global basis (e.g., globally remapping Ctrl+S to send Ctrl+D or something), such as the xbindkeys application. What I need, though, is a way to do this only for a specific application. For example, something like "Remap Ctrl+S to send Ctrl+D, but only in Chrome". Is there any way to accomplish this?
shortcut-keys x11
add a comment |
I'm aware of a number of ways of remapping key combinations in Ubuntu on a global basis (e.g., globally remapping Ctrl+S to send Ctrl+D or something), such as the xbindkeys application. What I need, though, is a way to do this only for a specific application. For example, something like "Remap Ctrl+S to send Ctrl+D, but only in Chrome". Is there any way to accomplish this?
shortcut-keys x11
Did you read this thread? I haven't tried it, but it seems to me to be exanctly what you are searching for. I don't know engouh about it to write a proper answer, though.
– lumbric
Jan 24 '12 at 15:19
add a comment |
I'm aware of a number of ways of remapping key combinations in Ubuntu on a global basis (e.g., globally remapping Ctrl+S to send Ctrl+D or something), such as the xbindkeys application. What I need, though, is a way to do this only for a specific application. For example, something like "Remap Ctrl+S to send Ctrl+D, but only in Chrome". Is there any way to accomplish this?
shortcut-keys x11
I'm aware of a number of ways of remapping key combinations in Ubuntu on a global basis (e.g., globally remapping Ctrl+S to send Ctrl+D or something), such as the xbindkeys application. What I need, though, is a way to do this only for a specific application. For example, something like "Remap Ctrl+S to send Ctrl+D, but only in Chrome". Is there any way to accomplish this?
shortcut-keys x11
shortcut-keys x11
asked Jan 20 '12 at 21:28
Derek ThurnDerek Thurn
9317
9317
Did you read this thread? I haven't tried it, but it seems to me to be exanctly what you are searching for. I don't know engouh about it to write a proper answer, though.
– lumbric
Jan 24 '12 at 15:19
add a comment |
Did you read this thread? I haven't tried it, but it seems to me to be exanctly what you are searching for. I don't know engouh about it to write a proper answer, though.
– lumbric
Jan 24 '12 at 15:19
Did you read this thread? I haven't tried it, but it seems to me to be exanctly what you are searching for. I don't know engouh about it to write a proper answer, though.
– lumbric
Jan 24 '12 at 15:19
Did you read this thread? I haven't tried it, but it seems to me to be exanctly what you are searching for. I don't know engouh about it to write a proper answer, though.
– lumbric
Jan 24 '12 at 15:19
add a comment |
2 Answers
2
active
oldest
votes
Your idea of using xbindkeys sounds good:
in your .xbindkeysrc
add a new keybinding:
"app_specific_keys.sh"
Control+s
This will execute "app_specific_keys.sh"
when you press ctrl+s
.
Now you need to define the script. It should get the active window and from that the name of the app which currently has the focus:
xprop -id `xdotool getactivewindow` |awk '/WM_CLASS/{print $4}'
This would do the trick: it asks xdotool for the active window, then asks xprop for all properties of the window with the given id, and then reduces the very verbose output to the name of the application (actually its class). If you run this in a gnome-terminal you would get
"Gnome-terminal"
Now you need to define actions for your applications:
if [ $N = '"Gnome-terminal"' ]; then
xdotool key --clearmodifiers ctrl+s
else
xdotool key --clearmodifiers ctrl+d
fi
So together, the script "app_specific_keys.sh"
could look like this:
#!/bin/bash
W=`xdotool getactivewindow`
S1=`xprop -id ${W} |awk '/WM_CLASS/{print $4}'`
S2='"Gnome-terminal"'
if [ $S1 = $S2 ]; then
xdotool key --clearmodifiers ctrl+d
else
xdotool key --clearmodifiers ctrl+s
fi
This should work, but as in this question, I have to admit that it does not. Probably because one of Compiz, Unity, Global Menu does not work well with the --clearmodifiers
option of xdotool. A workaround would be to add a sleep in front of your script in oder to be able to release the keys yourself:
In your .xbindkeysrc
change to this keybinding:
"sleep 0.5; app_specific_keys.sh"
Control+s
As a sidenote: this will not work, if you want to change keys for programs which run in a terminal (e.g. vi or emacs in console mode). The returned application class would still be "Gnome-terminal".
Hope that helps.
1
This ended up working just fine. I didn't use xdotool to send the keystrokes, I just usedxvkbd -xsendevent -text "Cs"
. This doesn't seem to suffer from the issues you were seeing with xdotool.
– Derek Thurn
Jan 30 '12 at 18:37
it's not possible to make a key call itself, likef
callingxdotool key f
. Still searching for a way to do this.
– Blauhirn
Mar 6 '16 at 23:07
ha, finally found one!xdotool type --window $(xdotool getwindowfocus) [keys]
using the --window option and sending to the currently active window will NOT lead to recursive behaviour.
– Blauhirn
Mar 6 '16 at 23:32
add a comment |
autokey is like AutoHotkey for Ubuntu. You can write scripts in python and have them execute via keyboard shortcut and a windows filter (making it pseudo-application specific). Your script can control keyboard and mouse events and even move windows around as an added touch.
autokey
is WAY faster thanxbindkeys
, even with window detection mode on - immediate action taken. Downside: Mouse button assignments seem to not work ( i think it's a bug)
– Blauhirn
Mar 13 '16 at 16:24
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2faskubuntu.com%2fquestions%2f97213%2fapplication-specific-key-combination-remapping%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your idea of using xbindkeys sounds good:
in your .xbindkeysrc
add a new keybinding:
"app_specific_keys.sh"
Control+s
This will execute "app_specific_keys.sh"
when you press ctrl+s
.
Now you need to define the script. It should get the active window and from that the name of the app which currently has the focus:
xprop -id `xdotool getactivewindow` |awk '/WM_CLASS/{print $4}'
This would do the trick: it asks xdotool for the active window, then asks xprop for all properties of the window with the given id, and then reduces the very verbose output to the name of the application (actually its class). If you run this in a gnome-terminal you would get
"Gnome-terminal"
Now you need to define actions for your applications:
if [ $N = '"Gnome-terminal"' ]; then
xdotool key --clearmodifiers ctrl+s
else
xdotool key --clearmodifiers ctrl+d
fi
So together, the script "app_specific_keys.sh"
could look like this:
#!/bin/bash
W=`xdotool getactivewindow`
S1=`xprop -id ${W} |awk '/WM_CLASS/{print $4}'`
S2='"Gnome-terminal"'
if [ $S1 = $S2 ]; then
xdotool key --clearmodifiers ctrl+d
else
xdotool key --clearmodifiers ctrl+s
fi
This should work, but as in this question, I have to admit that it does not. Probably because one of Compiz, Unity, Global Menu does not work well with the --clearmodifiers
option of xdotool. A workaround would be to add a sleep in front of your script in oder to be able to release the keys yourself:
In your .xbindkeysrc
change to this keybinding:
"sleep 0.5; app_specific_keys.sh"
Control+s
As a sidenote: this will not work, if you want to change keys for programs which run in a terminal (e.g. vi or emacs in console mode). The returned application class would still be "Gnome-terminal".
Hope that helps.
1
This ended up working just fine. I didn't use xdotool to send the keystrokes, I just usedxvkbd -xsendevent -text "Cs"
. This doesn't seem to suffer from the issues you were seeing with xdotool.
– Derek Thurn
Jan 30 '12 at 18:37
it's not possible to make a key call itself, likef
callingxdotool key f
. Still searching for a way to do this.
– Blauhirn
Mar 6 '16 at 23:07
ha, finally found one!xdotool type --window $(xdotool getwindowfocus) [keys]
using the --window option and sending to the currently active window will NOT lead to recursive behaviour.
– Blauhirn
Mar 6 '16 at 23:32
add a comment |
Your idea of using xbindkeys sounds good:
in your .xbindkeysrc
add a new keybinding:
"app_specific_keys.sh"
Control+s
This will execute "app_specific_keys.sh"
when you press ctrl+s
.
Now you need to define the script. It should get the active window and from that the name of the app which currently has the focus:
xprop -id `xdotool getactivewindow` |awk '/WM_CLASS/{print $4}'
This would do the trick: it asks xdotool for the active window, then asks xprop for all properties of the window with the given id, and then reduces the very verbose output to the name of the application (actually its class). If you run this in a gnome-terminal you would get
"Gnome-terminal"
Now you need to define actions for your applications:
if [ $N = '"Gnome-terminal"' ]; then
xdotool key --clearmodifiers ctrl+s
else
xdotool key --clearmodifiers ctrl+d
fi
So together, the script "app_specific_keys.sh"
could look like this:
#!/bin/bash
W=`xdotool getactivewindow`
S1=`xprop -id ${W} |awk '/WM_CLASS/{print $4}'`
S2='"Gnome-terminal"'
if [ $S1 = $S2 ]; then
xdotool key --clearmodifiers ctrl+d
else
xdotool key --clearmodifiers ctrl+s
fi
This should work, but as in this question, I have to admit that it does not. Probably because one of Compiz, Unity, Global Menu does not work well with the --clearmodifiers
option of xdotool. A workaround would be to add a sleep in front of your script in oder to be able to release the keys yourself:
In your .xbindkeysrc
change to this keybinding:
"sleep 0.5; app_specific_keys.sh"
Control+s
As a sidenote: this will not work, if you want to change keys for programs which run in a terminal (e.g. vi or emacs in console mode). The returned application class would still be "Gnome-terminal".
Hope that helps.
1
This ended up working just fine. I didn't use xdotool to send the keystrokes, I just usedxvkbd -xsendevent -text "Cs"
. This doesn't seem to suffer from the issues you were seeing with xdotool.
– Derek Thurn
Jan 30 '12 at 18:37
it's not possible to make a key call itself, likef
callingxdotool key f
. Still searching for a way to do this.
– Blauhirn
Mar 6 '16 at 23:07
ha, finally found one!xdotool type --window $(xdotool getwindowfocus) [keys]
using the --window option and sending to the currently active window will NOT lead to recursive behaviour.
– Blauhirn
Mar 6 '16 at 23:32
add a comment |
Your idea of using xbindkeys sounds good:
in your .xbindkeysrc
add a new keybinding:
"app_specific_keys.sh"
Control+s
This will execute "app_specific_keys.sh"
when you press ctrl+s
.
Now you need to define the script. It should get the active window and from that the name of the app which currently has the focus:
xprop -id `xdotool getactivewindow` |awk '/WM_CLASS/{print $4}'
This would do the trick: it asks xdotool for the active window, then asks xprop for all properties of the window with the given id, and then reduces the very verbose output to the name of the application (actually its class). If you run this in a gnome-terminal you would get
"Gnome-terminal"
Now you need to define actions for your applications:
if [ $N = '"Gnome-terminal"' ]; then
xdotool key --clearmodifiers ctrl+s
else
xdotool key --clearmodifiers ctrl+d
fi
So together, the script "app_specific_keys.sh"
could look like this:
#!/bin/bash
W=`xdotool getactivewindow`
S1=`xprop -id ${W} |awk '/WM_CLASS/{print $4}'`
S2='"Gnome-terminal"'
if [ $S1 = $S2 ]; then
xdotool key --clearmodifiers ctrl+d
else
xdotool key --clearmodifiers ctrl+s
fi
This should work, but as in this question, I have to admit that it does not. Probably because one of Compiz, Unity, Global Menu does not work well with the --clearmodifiers
option of xdotool. A workaround would be to add a sleep in front of your script in oder to be able to release the keys yourself:
In your .xbindkeysrc
change to this keybinding:
"sleep 0.5; app_specific_keys.sh"
Control+s
As a sidenote: this will not work, if you want to change keys for programs which run in a terminal (e.g. vi or emacs in console mode). The returned application class would still be "Gnome-terminal".
Hope that helps.
Your idea of using xbindkeys sounds good:
in your .xbindkeysrc
add a new keybinding:
"app_specific_keys.sh"
Control+s
This will execute "app_specific_keys.sh"
when you press ctrl+s
.
Now you need to define the script. It should get the active window and from that the name of the app which currently has the focus:
xprop -id `xdotool getactivewindow` |awk '/WM_CLASS/{print $4}'
This would do the trick: it asks xdotool for the active window, then asks xprop for all properties of the window with the given id, and then reduces the very verbose output to the name of the application (actually its class). If you run this in a gnome-terminal you would get
"Gnome-terminal"
Now you need to define actions for your applications:
if [ $N = '"Gnome-terminal"' ]; then
xdotool key --clearmodifiers ctrl+s
else
xdotool key --clearmodifiers ctrl+d
fi
So together, the script "app_specific_keys.sh"
could look like this:
#!/bin/bash
W=`xdotool getactivewindow`
S1=`xprop -id ${W} |awk '/WM_CLASS/{print $4}'`
S2='"Gnome-terminal"'
if [ $S1 = $S2 ]; then
xdotool key --clearmodifiers ctrl+d
else
xdotool key --clearmodifiers ctrl+s
fi
This should work, but as in this question, I have to admit that it does not. Probably because one of Compiz, Unity, Global Menu does not work well with the --clearmodifiers
option of xdotool. A workaround would be to add a sleep in front of your script in oder to be able to release the keys yourself:
In your .xbindkeysrc
change to this keybinding:
"sleep 0.5; app_specific_keys.sh"
Control+s
As a sidenote: this will not work, if you want to change keys for programs which run in a terminal (e.g. vi or emacs in console mode). The returned application class would still be "Gnome-terminal".
Hope that helps.
edited Apr 13 '17 at 12:24
Community♦
1
1
answered Jan 25 '12 at 9:46
xubuntixxubuntix
4,8701939
4,8701939
1
This ended up working just fine. I didn't use xdotool to send the keystrokes, I just usedxvkbd -xsendevent -text "Cs"
. This doesn't seem to suffer from the issues you were seeing with xdotool.
– Derek Thurn
Jan 30 '12 at 18:37
it's not possible to make a key call itself, likef
callingxdotool key f
. Still searching for a way to do this.
– Blauhirn
Mar 6 '16 at 23:07
ha, finally found one!xdotool type --window $(xdotool getwindowfocus) [keys]
using the --window option and sending to the currently active window will NOT lead to recursive behaviour.
– Blauhirn
Mar 6 '16 at 23:32
add a comment |
1
This ended up working just fine. I didn't use xdotool to send the keystrokes, I just usedxvkbd -xsendevent -text "Cs"
. This doesn't seem to suffer from the issues you were seeing with xdotool.
– Derek Thurn
Jan 30 '12 at 18:37
it's not possible to make a key call itself, likef
callingxdotool key f
. Still searching for a way to do this.
– Blauhirn
Mar 6 '16 at 23:07
ha, finally found one!xdotool type --window $(xdotool getwindowfocus) [keys]
using the --window option and sending to the currently active window will NOT lead to recursive behaviour.
– Blauhirn
Mar 6 '16 at 23:32
1
1
This ended up working just fine. I didn't use xdotool to send the keystrokes, I just used
xvkbd -xsendevent -text "Cs"
. This doesn't seem to suffer from the issues you were seeing with xdotool.– Derek Thurn
Jan 30 '12 at 18:37
This ended up working just fine. I didn't use xdotool to send the keystrokes, I just used
xvkbd -xsendevent -text "Cs"
. This doesn't seem to suffer from the issues you were seeing with xdotool.– Derek Thurn
Jan 30 '12 at 18:37
it's not possible to make a key call itself, like
f
calling xdotool key f
. Still searching for a way to do this.– Blauhirn
Mar 6 '16 at 23:07
it's not possible to make a key call itself, like
f
calling xdotool key f
. Still searching for a way to do this.– Blauhirn
Mar 6 '16 at 23:07
ha, finally found one!
xdotool type --window $(xdotool getwindowfocus) [keys]
using the --window option and sending to the currently active window will NOT lead to recursive behaviour.– Blauhirn
Mar 6 '16 at 23:32
ha, finally found one!
xdotool type --window $(xdotool getwindowfocus) [keys]
using the --window option and sending to the currently active window will NOT lead to recursive behaviour.– Blauhirn
Mar 6 '16 at 23:32
add a comment |
autokey is like AutoHotkey for Ubuntu. You can write scripts in python and have them execute via keyboard shortcut and a windows filter (making it pseudo-application specific). Your script can control keyboard and mouse events and even move windows around as an added touch.
autokey
is WAY faster thanxbindkeys
, even with window detection mode on - immediate action taken. Downside: Mouse button assignments seem to not work ( i think it's a bug)
– Blauhirn
Mar 13 '16 at 16:24
add a comment |
autokey is like AutoHotkey for Ubuntu. You can write scripts in python and have them execute via keyboard shortcut and a windows filter (making it pseudo-application specific). Your script can control keyboard and mouse events and even move windows around as an added touch.
autokey
is WAY faster thanxbindkeys
, even with window detection mode on - immediate action taken. Downside: Mouse button assignments seem to not work ( i think it's a bug)
– Blauhirn
Mar 13 '16 at 16:24
add a comment |
autokey is like AutoHotkey for Ubuntu. You can write scripts in python and have them execute via keyboard shortcut and a windows filter (making it pseudo-application specific). Your script can control keyboard and mouse events and even move windows around as an added touch.
autokey is like AutoHotkey for Ubuntu. You can write scripts in python and have them execute via keyboard shortcut and a windows filter (making it pseudo-application specific). Your script can control keyboard and mouse events and even move windows around as an added touch.
edited 12 hours ago
Shai Coleman
1031
1031
answered Jan 26 '12 at 19:50
aramadiaaramadia
1212
1212
autokey
is WAY faster thanxbindkeys
, even with window detection mode on - immediate action taken. Downside: Mouse button assignments seem to not work ( i think it's a bug)
– Blauhirn
Mar 13 '16 at 16:24
add a comment |
autokey
is WAY faster thanxbindkeys
, even with window detection mode on - immediate action taken. Downside: Mouse button assignments seem to not work ( i think it's a bug)
– Blauhirn
Mar 13 '16 at 16:24
autokey
is WAY faster than xbindkeys
, even with window detection mode on - immediate action taken. Downside: Mouse button assignments seem to not work ( i think it's a bug)– Blauhirn
Mar 13 '16 at 16:24
autokey
is WAY faster than xbindkeys
, even with window detection mode on - immediate action taken. Downside: Mouse button assignments seem to not work ( i think it's a bug)– Blauhirn
Mar 13 '16 at 16:24
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f97213%2fapplication-specific-key-combination-remapping%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
Did you read this thread? I haven't tried it, but it seems to me to be exanctly what you are searching for. I don't know engouh about it to write a proper answer, though.
– lumbric
Jan 24 '12 at 15:19