How to simulate a key press in an out of focus window
I'm looking for a way to simulate a key press in an out of focus window.
More specifically, I need to press a key every x seconds in a browser page for a given amount of time. It should look like a simple key press while on the webpage without any input field selected.
I'm currently doing this with a simple AHK script, but I can't use the laptop meanwhile because I need to leave the browser's page in focus.
Do you have any ideas about that? Thank you.
edit:
If it can help, there are two options in this webpage that I can select using the keys "0" and "1", and I would like to be able to select one of them while the window is minimized or in background.
keyboard script autohotkey simulation
add a comment |
I'm looking for a way to simulate a key press in an out of focus window.
More specifically, I need to press a key every x seconds in a browser page for a given amount of time. It should look like a simple key press while on the webpage without any input field selected.
I'm currently doing this with a simple AHK script, but I can't use the laptop meanwhile because I need to leave the browser's page in focus.
Do you have any ideas about that? Thank you.
edit:
If it can help, there are two options in this webpage that I can select using the keys "0" and "1", and I would like to be able to select one of them while the window is minimized or in background.
keyboard script autohotkey simulation
Doesn't your script work without focus? It would be a good idea to show us this script.
– harrymc
Jan 9 at 21:25
My original script uses a simple "Send" command. I also tried ControlSend as suggested in the other answer, but it doesn't seem to fit my needs.
– Francesco Villano
Jan 10 at 13:05
add a comment |
I'm looking for a way to simulate a key press in an out of focus window.
More specifically, I need to press a key every x seconds in a browser page for a given amount of time. It should look like a simple key press while on the webpage without any input field selected.
I'm currently doing this with a simple AHK script, but I can't use the laptop meanwhile because I need to leave the browser's page in focus.
Do you have any ideas about that? Thank you.
edit:
If it can help, there are two options in this webpage that I can select using the keys "0" and "1", and I would like to be able to select one of them while the window is minimized or in background.
keyboard script autohotkey simulation
I'm looking for a way to simulate a key press in an out of focus window.
More specifically, I need to press a key every x seconds in a browser page for a given amount of time. It should look like a simple key press while on the webpage without any input field selected.
I'm currently doing this with a simple AHK script, but I can't use the laptop meanwhile because I need to leave the browser's page in focus.
Do you have any ideas about that? Thank you.
edit:
If it can help, there are two options in this webpage that I can select using the keys "0" and "1", and I would like to be able to select one of them while the window is minimized or in background.
keyboard script autohotkey simulation
keyboard script autohotkey simulation
edited Jan 10 at 13:08
Francesco Villano
asked Jan 9 at 20:48
Francesco VillanoFrancesco Villano
112
112
Doesn't your script work without focus? It would be a good idea to show us this script.
– harrymc
Jan 9 at 21:25
My original script uses a simple "Send" command. I also tried ControlSend as suggested in the other answer, but it doesn't seem to fit my needs.
– Francesco Villano
Jan 10 at 13:05
add a comment |
Doesn't your script work without focus? It would be a good idea to show us this script.
– harrymc
Jan 9 at 21:25
My original script uses a simple "Send" command. I also tried ControlSend as suggested in the other answer, but it doesn't seem to fit my needs.
– Francesco Villano
Jan 10 at 13:05
Doesn't your script work without focus? It would be a good idea to show us this script.
– harrymc
Jan 9 at 21:25
Doesn't your script work without focus? It would be a good idea to show us this script.
– harrymc
Jan 9 at 21:25
My original script uses a simple "Send" command. I also tried ControlSend as suggested in the other answer, but it doesn't seem to fit my needs.
– Francesco Villano
Jan 10 at 13:05
My original script uses a simple "Send" command. I also tried ControlSend as suggested in the other answer, but it doesn't seem to fit my needs.
– Francesco Villano
Jan 10 at 13:05
add a comment |
1 Answer
1
active
oldest
votes
Example:
Simulate a key press (send the key "a") in an (out of focus or minimized) notepad window every 2 seconds:
Loop
{
ControlSend,, a, ahk_class Notepad
Sleep, 2000 ; 2 seconds
}
https://autohotkey.com/docs/commands/ControlSend.htm
Instead of Loop you can use SetTimer.
I tried this method but it doesn't work. I'll try to be more specific: in the browser page there are two options that I can select with the keys "0" and "1"; with ControlSend I found that an option is selected only if the windows is in focus.
– Francesco Villano
Jan 10 at 13:01
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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%2fsuperuser.com%2fquestions%2f1392439%2fhow-to-simulate-a-key-press-in-an-out-of-focus-window%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
Example:
Simulate a key press (send the key "a") in an (out of focus or minimized) notepad window every 2 seconds:
Loop
{
ControlSend,, a, ahk_class Notepad
Sleep, 2000 ; 2 seconds
}
https://autohotkey.com/docs/commands/ControlSend.htm
Instead of Loop you can use SetTimer.
I tried this method but it doesn't work. I'll try to be more specific: in the browser page there are two options that I can select with the keys "0" and "1"; with ControlSend I found that an option is selected only if the windows is in focus.
– Francesco Villano
Jan 10 at 13:01
add a comment |
Example:
Simulate a key press (send the key "a") in an (out of focus or minimized) notepad window every 2 seconds:
Loop
{
ControlSend,, a, ahk_class Notepad
Sleep, 2000 ; 2 seconds
}
https://autohotkey.com/docs/commands/ControlSend.htm
Instead of Loop you can use SetTimer.
I tried this method but it doesn't work. I'll try to be more specific: in the browser page there are two options that I can select with the keys "0" and "1"; with ControlSend I found that an option is selected only if the windows is in focus.
– Francesco Villano
Jan 10 at 13:01
add a comment |
Example:
Simulate a key press (send the key "a") in an (out of focus or minimized) notepad window every 2 seconds:
Loop
{
ControlSend,, a, ahk_class Notepad
Sleep, 2000 ; 2 seconds
}
https://autohotkey.com/docs/commands/ControlSend.htm
Instead of Loop you can use SetTimer.
Example:
Simulate a key press (send the key "a") in an (out of focus or minimized) notepad window every 2 seconds:
Loop
{
ControlSend,, a, ahk_class Notepad
Sleep, 2000 ; 2 seconds
}
https://autohotkey.com/docs/commands/ControlSend.htm
Instead of Loop you can use SetTimer.
answered Jan 10 at 7:43
user3419297user3419297
1,771267
1,771267
I tried this method but it doesn't work. I'll try to be more specific: in the browser page there are two options that I can select with the keys "0" and "1"; with ControlSend I found that an option is selected only if the windows is in focus.
– Francesco Villano
Jan 10 at 13:01
add a comment |
I tried this method but it doesn't work. I'll try to be more specific: in the browser page there are two options that I can select with the keys "0" and "1"; with ControlSend I found that an option is selected only if the windows is in focus.
– Francesco Villano
Jan 10 at 13:01
I tried this method but it doesn't work. I'll try to be more specific: in the browser page there are two options that I can select with the keys "0" and "1"; with ControlSend I found that an option is selected only if the windows is in focus.
– Francesco Villano
Jan 10 at 13:01
I tried this method but it doesn't work. I'll try to be more specific: in the browser page there are two options that I can select with the keys "0" and "1"; with ControlSend I found that an option is selected only if the windows is in focus.
– Francesco Villano
Jan 10 at 13:01
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f1392439%2fhow-to-simulate-a-key-press-in-an-out-of-focus-window%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
Doesn't your script work without focus? It would be a good idea to show us this script.
– harrymc
Jan 9 at 21:25
My original script uses a simple "Send" command. I also tried ControlSend as suggested in the other answer, but it doesn't seem to fit my needs.
– Francesco Villano
Jan 10 at 13:05