How can I programatically show/hide my app window with global shortcut key?
I'm writing a Notational Velocity clone for Gnome/Ubuntu using Quickly (PyGI) and I want to allow users to set a global shortcut key that will toggle the visibility of the app window when the app is running (something like Tilda does for its terminal emulator). I.e., once the app is launched, a user could press F2 to hide the window, and then press F2 again to make it visible and bring it to the front. I don't want to use an external hotkey app or anything that requires out-of-app settings. How would I go about this?
There's a similar question here: How can I listen on global keypress event? but the main answer there is a cludgy non-programmatic solution. One commenter mentions "grabbing the keyboard with an X api call" but I'm not sure where to start with that.
shortcut-keys application-development gtk pygi
add a comment |
I'm writing a Notational Velocity clone for Gnome/Ubuntu using Quickly (PyGI) and I want to allow users to set a global shortcut key that will toggle the visibility of the app window when the app is running (something like Tilda does for its terminal emulator). I.e., once the app is launched, a user could press F2 to hide the window, and then press F2 again to make it visible and bring it to the front. I don't want to use an external hotkey app or anything that requires out-of-app settings. How would I go about this?
There's a similar question here: How can I listen on global keypress event? but the main answer there is a cludgy non-programmatic solution. One commenter mentions "grabbing the keyboard with an X api call" but I'm not sure where to start with that.
shortcut-keys application-development gtk pygi
How about modifying gconf settings for compiz to switch focus to your app? I think user keybindings are stored here. Problem is that once your app is out of focus, I don't think it will receive the keypress events. Using compiz settings could circumvent that.
– Ian B.
Jul 27 '12 at 19:28
@Ian B., I'm not sure that's something that I can build into an app programatically. I don't want to do this just for my own use, but to build it into a distributable application (as in Tilda, Qnotero, Guake, etc.)
– monotasker
Aug 9 '12 at 13:09
1
The Keybinder library does exactly this: github.com/engla/keybinder if you check pull requests there are requests in for examples using pygi.
– RobotHumans
Feb 23 '14 at 11:04
Thanks @hbdgaf. If you submit that as an answer I'll accept it, since it's the first answer I've received that really does what I'm asking.
– monotasker
Feb 23 '14 at 17:31
I'm just sorry it took this long. It's a lib I'm using at the moment.
– RobotHumans
Feb 23 '14 at 17:38
add a comment |
I'm writing a Notational Velocity clone for Gnome/Ubuntu using Quickly (PyGI) and I want to allow users to set a global shortcut key that will toggle the visibility of the app window when the app is running (something like Tilda does for its terminal emulator). I.e., once the app is launched, a user could press F2 to hide the window, and then press F2 again to make it visible and bring it to the front. I don't want to use an external hotkey app or anything that requires out-of-app settings. How would I go about this?
There's a similar question here: How can I listen on global keypress event? but the main answer there is a cludgy non-programmatic solution. One commenter mentions "grabbing the keyboard with an X api call" but I'm not sure where to start with that.
shortcut-keys application-development gtk pygi
I'm writing a Notational Velocity clone for Gnome/Ubuntu using Quickly (PyGI) and I want to allow users to set a global shortcut key that will toggle the visibility of the app window when the app is running (something like Tilda does for its terminal emulator). I.e., once the app is launched, a user could press F2 to hide the window, and then press F2 again to make it visible and bring it to the front. I don't want to use an external hotkey app or anything that requires out-of-app settings. How would I go about this?
There's a similar question here: How can I listen on global keypress event? but the main answer there is a cludgy non-programmatic solution. One commenter mentions "grabbing the keyboard with an X api call" but I'm not sure where to start with that.
shortcut-keys application-development gtk pygi
shortcut-keys application-development gtk pygi
edited Apr 13 '17 at 12:23
Community♦
1
1
asked Jul 21 '12 at 19:19
monotaskermonotasker
2,67411214
2,67411214
How about modifying gconf settings for compiz to switch focus to your app? I think user keybindings are stored here. Problem is that once your app is out of focus, I don't think it will receive the keypress events. Using compiz settings could circumvent that.
– Ian B.
Jul 27 '12 at 19:28
@Ian B., I'm not sure that's something that I can build into an app programatically. I don't want to do this just for my own use, but to build it into a distributable application (as in Tilda, Qnotero, Guake, etc.)
– monotasker
Aug 9 '12 at 13:09
1
The Keybinder library does exactly this: github.com/engla/keybinder if you check pull requests there are requests in for examples using pygi.
– RobotHumans
Feb 23 '14 at 11:04
Thanks @hbdgaf. If you submit that as an answer I'll accept it, since it's the first answer I've received that really does what I'm asking.
– monotasker
Feb 23 '14 at 17:31
I'm just sorry it took this long. It's a lib I'm using at the moment.
– RobotHumans
Feb 23 '14 at 17:38
add a comment |
How about modifying gconf settings for compiz to switch focus to your app? I think user keybindings are stored here. Problem is that once your app is out of focus, I don't think it will receive the keypress events. Using compiz settings could circumvent that.
– Ian B.
Jul 27 '12 at 19:28
@Ian B., I'm not sure that's something that I can build into an app programatically. I don't want to do this just for my own use, but to build it into a distributable application (as in Tilda, Qnotero, Guake, etc.)
– monotasker
Aug 9 '12 at 13:09
1
The Keybinder library does exactly this: github.com/engla/keybinder if you check pull requests there are requests in for examples using pygi.
– RobotHumans
Feb 23 '14 at 11:04
Thanks @hbdgaf. If you submit that as an answer I'll accept it, since it's the first answer I've received that really does what I'm asking.
– monotasker
Feb 23 '14 at 17:31
I'm just sorry it took this long. It's a lib I'm using at the moment.
– RobotHumans
Feb 23 '14 at 17:38
How about modifying gconf settings for compiz to switch focus to your app? I think user keybindings are stored here. Problem is that once your app is out of focus, I don't think it will receive the keypress events. Using compiz settings could circumvent that.
– Ian B.
Jul 27 '12 at 19:28
How about modifying gconf settings for compiz to switch focus to your app? I think user keybindings are stored here. Problem is that once your app is out of focus, I don't think it will receive the keypress events. Using compiz settings could circumvent that.
– Ian B.
Jul 27 '12 at 19:28
@Ian B., I'm not sure that's something that I can build into an app programatically. I don't want to do this just for my own use, but to build it into a distributable application (as in Tilda, Qnotero, Guake, etc.)
– monotasker
Aug 9 '12 at 13:09
@Ian B., I'm not sure that's something that I can build into an app programatically. I don't want to do this just for my own use, but to build it into a distributable application (as in Tilda, Qnotero, Guake, etc.)
– monotasker
Aug 9 '12 at 13:09
1
1
The Keybinder library does exactly this: github.com/engla/keybinder if you check pull requests there are requests in for examples using pygi.
– RobotHumans
Feb 23 '14 at 11:04
The Keybinder library does exactly this: github.com/engla/keybinder if you check pull requests there are requests in for examples using pygi.
– RobotHumans
Feb 23 '14 at 11:04
Thanks @hbdgaf. If you submit that as an answer I'll accept it, since it's the first answer I've received that really does what I'm asking.
– monotasker
Feb 23 '14 at 17:31
Thanks @hbdgaf. If you submit that as an answer I'll accept it, since it's the first answer I've received that really does what I'm asking.
– monotasker
Feb 23 '14 at 17:31
I'm just sorry it took this long. It's a lib I'm using at the moment.
– RobotHumans
Feb 23 '14 at 17:38
I'm just sorry it took this long. It's a lib I'm using at the moment.
– RobotHumans
Feb 23 '14 at 17:38
add a comment |
2 Answers
2
active
oldest
votes
The Keybinder library does exactly this. If you check pull requests there are requests in for examples using pygi, one of which is me for py3k.
add a comment |
I realize this is an external setting, not in app, but I thought I'd write how to do this since I couldn't find documentation online.
I needed to read some compiz settings recently for my program, so figuring out how to change them was fairly straightforward. You can programatically set compiz settings in python using python-compizconfig. I've played with it a little bit and you can set values like so:
import compizconfig
context=compizconfig.Context()
commandplugin=context.Plugins['commands']
c0=commandplugin.Screen['command0']
c0.Value='xeyes'
key0=commandplugin.Screen['run_command0_key']
key0.Value='<Control><Primary>g'
context.Write() #Note that sometimes you have to pass False to get it to update settings
The above sets the commands plugin of compiz to run xeyes using control-g keycombination. You'd probably have to do a check to make sure that the plugin was running (mine was off in ccsm by default). Note that to get many of the settings you can use the keys()
function to list them (i.e.) context.Plugins.keys()
Here's a link to code that helped me figure out how this works, since I can't find any documentation: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/precise/compizconfig-python/precise/view/head:/src/compizconfig.pyx
When you say this is "an external setting" it looks like an app could set this programmatically. It makes the app dependent on compiz for its hotkey, but this is the closest I've seen to what I'm looking for without getting into some low-level X hocus pocus that is beyond me right now. Thanks.
– monotasker
Sep 26 '12 at 21:48
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%2f166464%2fhow-can-i-programatically-show-hide-my-app-window-with-global-shortcut-key%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
The Keybinder library does exactly this. If you check pull requests there are requests in for examples using pygi, one of which is me for py3k.
add a comment |
The Keybinder library does exactly this. If you check pull requests there are requests in for examples using pygi, one of which is me for py3k.
add a comment |
The Keybinder library does exactly this. If you check pull requests there are requests in for examples using pygi, one of which is me for py3k.
The Keybinder library does exactly this. If you check pull requests there are requests in for examples using pygi, one of which is me for py3k.
answered Feb 23 '14 at 17:37
RobotHumansRobotHumans
23.1k363104
23.1k363104
add a comment |
add a comment |
I realize this is an external setting, not in app, but I thought I'd write how to do this since I couldn't find documentation online.
I needed to read some compiz settings recently for my program, so figuring out how to change them was fairly straightforward. You can programatically set compiz settings in python using python-compizconfig. I've played with it a little bit and you can set values like so:
import compizconfig
context=compizconfig.Context()
commandplugin=context.Plugins['commands']
c0=commandplugin.Screen['command0']
c0.Value='xeyes'
key0=commandplugin.Screen['run_command0_key']
key0.Value='<Control><Primary>g'
context.Write() #Note that sometimes you have to pass False to get it to update settings
The above sets the commands plugin of compiz to run xeyes using control-g keycombination. You'd probably have to do a check to make sure that the plugin was running (mine was off in ccsm by default). Note that to get many of the settings you can use the keys()
function to list them (i.e.) context.Plugins.keys()
Here's a link to code that helped me figure out how this works, since I can't find any documentation: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/precise/compizconfig-python/precise/view/head:/src/compizconfig.pyx
When you say this is "an external setting" it looks like an app could set this programmatically. It makes the app dependent on compiz for its hotkey, but this is the closest I've seen to what I'm looking for without getting into some low-level X hocus pocus that is beyond me right now. Thanks.
– monotasker
Sep 26 '12 at 21:48
add a comment |
I realize this is an external setting, not in app, but I thought I'd write how to do this since I couldn't find documentation online.
I needed to read some compiz settings recently for my program, so figuring out how to change them was fairly straightforward. You can programatically set compiz settings in python using python-compizconfig. I've played with it a little bit and you can set values like so:
import compizconfig
context=compizconfig.Context()
commandplugin=context.Plugins['commands']
c0=commandplugin.Screen['command0']
c0.Value='xeyes'
key0=commandplugin.Screen['run_command0_key']
key0.Value='<Control><Primary>g'
context.Write() #Note that sometimes you have to pass False to get it to update settings
The above sets the commands plugin of compiz to run xeyes using control-g keycombination. You'd probably have to do a check to make sure that the plugin was running (mine was off in ccsm by default). Note that to get many of the settings you can use the keys()
function to list them (i.e.) context.Plugins.keys()
Here's a link to code that helped me figure out how this works, since I can't find any documentation: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/precise/compizconfig-python/precise/view/head:/src/compizconfig.pyx
When you say this is "an external setting" it looks like an app could set this programmatically. It makes the app dependent on compiz for its hotkey, but this is the closest I've seen to what I'm looking for without getting into some low-level X hocus pocus that is beyond me right now. Thanks.
– monotasker
Sep 26 '12 at 21:48
add a comment |
I realize this is an external setting, not in app, but I thought I'd write how to do this since I couldn't find documentation online.
I needed to read some compiz settings recently for my program, so figuring out how to change them was fairly straightforward. You can programatically set compiz settings in python using python-compizconfig. I've played with it a little bit and you can set values like so:
import compizconfig
context=compizconfig.Context()
commandplugin=context.Plugins['commands']
c0=commandplugin.Screen['command0']
c0.Value='xeyes'
key0=commandplugin.Screen['run_command0_key']
key0.Value='<Control><Primary>g'
context.Write() #Note that sometimes you have to pass False to get it to update settings
The above sets the commands plugin of compiz to run xeyes using control-g keycombination. You'd probably have to do a check to make sure that the plugin was running (mine was off in ccsm by default). Note that to get many of the settings you can use the keys()
function to list them (i.e.) context.Plugins.keys()
Here's a link to code that helped me figure out how this works, since I can't find any documentation: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/precise/compizconfig-python/precise/view/head:/src/compizconfig.pyx
I realize this is an external setting, not in app, but I thought I'd write how to do this since I couldn't find documentation online.
I needed to read some compiz settings recently for my program, so figuring out how to change them was fairly straightforward. You can programatically set compiz settings in python using python-compizconfig. I've played with it a little bit and you can set values like so:
import compizconfig
context=compizconfig.Context()
commandplugin=context.Plugins['commands']
c0=commandplugin.Screen['command0']
c0.Value='xeyes'
key0=commandplugin.Screen['run_command0_key']
key0.Value='<Control><Primary>g'
context.Write() #Note that sometimes you have to pass False to get it to update settings
The above sets the commands plugin of compiz to run xeyes using control-g keycombination. You'd probably have to do a check to make sure that the plugin was running (mine was off in ccsm by default). Note that to get many of the settings you can use the keys()
function to list them (i.e.) context.Plugins.keys()
Here's a link to code that helped me figure out how this works, since I can't find any documentation: http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/precise/compizconfig-python/precise/view/head:/src/compizconfig.pyx
answered Aug 20 '12 at 2:56
Ian B.Ian B.
3,1481425
3,1481425
When you say this is "an external setting" it looks like an app could set this programmatically. It makes the app dependent on compiz for its hotkey, but this is the closest I've seen to what I'm looking for without getting into some low-level X hocus pocus that is beyond me right now. Thanks.
– monotasker
Sep 26 '12 at 21:48
add a comment |
When you say this is "an external setting" it looks like an app could set this programmatically. It makes the app dependent on compiz for its hotkey, but this is the closest I've seen to what I'm looking for without getting into some low-level X hocus pocus that is beyond me right now. Thanks.
– monotasker
Sep 26 '12 at 21:48
When you say this is "an external setting" it looks like an app could set this programmatically. It makes the app dependent on compiz for its hotkey, but this is the closest I've seen to what I'm looking for without getting into some low-level X hocus pocus that is beyond me right now. Thanks.
– monotasker
Sep 26 '12 at 21:48
When you say this is "an external setting" it looks like an app could set this programmatically. It makes the app dependent on compiz for its hotkey, but this is the closest I've seen to what I'm looking for without getting into some low-level X hocus pocus that is beyond me right now. Thanks.
– monotasker
Sep 26 '12 at 21:48
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%2f166464%2fhow-can-i-programatically-show-hide-my-app-window-with-global-shortcut-key%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
How about modifying gconf settings for compiz to switch focus to your app? I think user keybindings are stored here. Problem is that once your app is out of focus, I don't think it will receive the keypress events. Using compiz settings could circumvent that.
– Ian B.
Jul 27 '12 at 19:28
@Ian B., I'm not sure that's something that I can build into an app programatically. I don't want to do this just for my own use, but to build it into a distributable application (as in Tilda, Qnotero, Guake, etc.)
– monotasker
Aug 9 '12 at 13:09
1
The Keybinder library does exactly this: github.com/engla/keybinder if you check pull requests there are requests in for examples using pygi.
– RobotHumans
Feb 23 '14 at 11:04
Thanks @hbdgaf. If you submit that as an answer I'll accept it, since it's the first answer I've received that really does what I'm asking.
– monotasker
Feb 23 '14 at 17:31
I'm just sorry it took this long. It's a lib I'm using at the moment.
– RobotHumans
Feb 23 '14 at 17:38