pynput module right key press not working?
I have been trying all day to figure a way to automate the process of toggling on the new Windows 10 Mobile Hotspot setting, possibly using python 3, which you can find by navigating to Settings -> Network & Internet -> Mobile Hotspot -> The first toggle.
After spending almost the whole day, trying to find information such as, what registry key the toggle alters, to make it enable/disable the Mobile hotspot and googling to find articles that show some command prompt, power shell, etc. method to enable this this setting, I have been unsuccessful at finding a direct solution for automating the toggling of the toggle switch which either enables/ disables the Mobile Hotspot.
So I finally decided, to use a keypress module, pynput
in python 3, to automate the key presses I would need to make to go and toggle the setting. So using this module I wrote the following script:
def enableMobileHotspot():
keyboard = Controller()
#Open Settings
print("Opening Settings")
keyboard.press(Key.cmd) #Key.cmd = Windows Key
keyboard.press("i")
keyboard.release(Key.cmd)
keyboard.release("i")
time.sleep(3)
#Navigate to Network & Internet
print("Navigating to Network & Internet")
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.3)
keyboard.press(Key.right)
time.sleep(0.3)
keyboard.release(Key.right)
time.sleep(0.3)
keyboard.press(Key.right)
keyboard.release(Key.right)
time.sleep(0.3)
keyboard.press(Key.right)
keyboard.release(Key.right)
time.sleep(0.3)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(1)
#Navigate to Mobile hotspot
print("Navigating to Mobile Hotspot")
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(15)
#Go To Toggle and Enable/ Disable Toggle
print("Navigating to Toggle and Enabling Mobile Hotspot")
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.3)
keyboard.press(Key.space)
keyboard.release(Key.space)
time.sleep(15)
# Close Setting Window
print("Closing Settings")
keyboard.press(Key.alt)
keyboard.press(Key.f4)
keyboard.release(Key.alt)
keyboard.release(Key.f4)
enableMobileHotspot()
The issue, I am facing with this script is that for some reason the command keyboard.press(Key.right)
just doesn't seem to work, for the Navigate to Network & Internet
process, as after executing the "tab" key press command, it simply stuck on the first settings option, i.e. System
. This is bad, because then the rest of the key press commands are occurring on the wrong settings.
I thought the issue may possibly be due to the key being pressed and released quite quickly, and therefore I tried to put some `time.sleep()' between the commands, but even that doesn't help.
I only need this script to ensure my laptop can automatically toggle the option, when its been restarted, as I use it to extend the WiFi at home.
If anybody has a solution as to why the right key command is not working I would really appreciate the help.
Thank you.
python python-3.x pynput
add a comment |
I have been trying all day to figure a way to automate the process of toggling on the new Windows 10 Mobile Hotspot setting, possibly using python 3, which you can find by navigating to Settings -> Network & Internet -> Mobile Hotspot -> The first toggle.
After spending almost the whole day, trying to find information such as, what registry key the toggle alters, to make it enable/disable the Mobile hotspot and googling to find articles that show some command prompt, power shell, etc. method to enable this this setting, I have been unsuccessful at finding a direct solution for automating the toggling of the toggle switch which either enables/ disables the Mobile Hotspot.
So I finally decided, to use a keypress module, pynput
in python 3, to automate the key presses I would need to make to go and toggle the setting. So using this module I wrote the following script:
def enableMobileHotspot():
keyboard = Controller()
#Open Settings
print("Opening Settings")
keyboard.press(Key.cmd) #Key.cmd = Windows Key
keyboard.press("i")
keyboard.release(Key.cmd)
keyboard.release("i")
time.sleep(3)
#Navigate to Network & Internet
print("Navigating to Network & Internet")
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.3)
keyboard.press(Key.right)
time.sleep(0.3)
keyboard.release(Key.right)
time.sleep(0.3)
keyboard.press(Key.right)
keyboard.release(Key.right)
time.sleep(0.3)
keyboard.press(Key.right)
keyboard.release(Key.right)
time.sleep(0.3)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(1)
#Navigate to Mobile hotspot
print("Navigating to Mobile Hotspot")
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(15)
#Go To Toggle and Enable/ Disable Toggle
print("Navigating to Toggle and Enabling Mobile Hotspot")
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.3)
keyboard.press(Key.space)
keyboard.release(Key.space)
time.sleep(15)
# Close Setting Window
print("Closing Settings")
keyboard.press(Key.alt)
keyboard.press(Key.f4)
keyboard.release(Key.alt)
keyboard.release(Key.f4)
enableMobileHotspot()
The issue, I am facing with this script is that for some reason the command keyboard.press(Key.right)
just doesn't seem to work, for the Navigate to Network & Internet
process, as after executing the "tab" key press command, it simply stuck on the first settings option, i.e. System
. This is bad, because then the rest of the key press commands are occurring on the wrong settings.
I thought the issue may possibly be due to the key being pressed and released quite quickly, and therefore I tried to put some `time.sleep()' between the commands, but even that doesn't help.
I only need this script to ensure my laptop can automatically toggle the option, when its been restarted, as I use it to extend the WiFi at home.
If anybody has a solution as to why the right key command is not working I would really appreciate the help.
Thank you.
python python-3.x pynput
have youu looked ctypes? docs.python.org/3/library/ctypes.html
– Jack Herer
Nov 12 '18 at 1:00
@JackHerer Thankyou for your reply, never heard of ctypes before if I am honest. Having looked at it, I don't get how I can use it, kindly please explain more, if you know of a way I can make use of it. Thanks
– SShah
Nov 12 '18 at 1:07
Ill be honest I have never needed to use ctypes for windows because i avoid windows like the plague!! I just know its very powerful, and in my opinion using windows mobile hotspot as a wifi extender is not the best way forward, why not get a free/cheap router that is an old ISP router and just make an extender from that? Sorry I cant be of much help other than that.
– Jack Herer
Nov 12 '18 at 1:21
@JackHerer Oh okay thanks, and its ok no problem, Thank you very much for all the support. I just need to extend the wifi temporarily therefore not bothered to purchase a cheap extender. Surprisingly, what I am finding, compared to a cheap repeater which I have used in the past, this mobile hotspot, seems more faster and stable.
– SShah
Nov 12 '18 at 9:39
add a comment |
I have been trying all day to figure a way to automate the process of toggling on the new Windows 10 Mobile Hotspot setting, possibly using python 3, which you can find by navigating to Settings -> Network & Internet -> Mobile Hotspot -> The first toggle.
After spending almost the whole day, trying to find information such as, what registry key the toggle alters, to make it enable/disable the Mobile hotspot and googling to find articles that show some command prompt, power shell, etc. method to enable this this setting, I have been unsuccessful at finding a direct solution for automating the toggling of the toggle switch which either enables/ disables the Mobile Hotspot.
So I finally decided, to use a keypress module, pynput
in python 3, to automate the key presses I would need to make to go and toggle the setting. So using this module I wrote the following script:
def enableMobileHotspot():
keyboard = Controller()
#Open Settings
print("Opening Settings")
keyboard.press(Key.cmd) #Key.cmd = Windows Key
keyboard.press("i")
keyboard.release(Key.cmd)
keyboard.release("i")
time.sleep(3)
#Navigate to Network & Internet
print("Navigating to Network & Internet")
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.3)
keyboard.press(Key.right)
time.sleep(0.3)
keyboard.release(Key.right)
time.sleep(0.3)
keyboard.press(Key.right)
keyboard.release(Key.right)
time.sleep(0.3)
keyboard.press(Key.right)
keyboard.release(Key.right)
time.sleep(0.3)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(1)
#Navigate to Mobile hotspot
print("Navigating to Mobile Hotspot")
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(15)
#Go To Toggle and Enable/ Disable Toggle
print("Navigating to Toggle and Enabling Mobile Hotspot")
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.3)
keyboard.press(Key.space)
keyboard.release(Key.space)
time.sleep(15)
# Close Setting Window
print("Closing Settings")
keyboard.press(Key.alt)
keyboard.press(Key.f4)
keyboard.release(Key.alt)
keyboard.release(Key.f4)
enableMobileHotspot()
The issue, I am facing with this script is that for some reason the command keyboard.press(Key.right)
just doesn't seem to work, for the Navigate to Network & Internet
process, as after executing the "tab" key press command, it simply stuck on the first settings option, i.e. System
. This is bad, because then the rest of the key press commands are occurring on the wrong settings.
I thought the issue may possibly be due to the key being pressed and released quite quickly, and therefore I tried to put some `time.sleep()' between the commands, but even that doesn't help.
I only need this script to ensure my laptop can automatically toggle the option, when its been restarted, as I use it to extend the WiFi at home.
If anybody has a solution as to why the right key command is not working I would really appreciate the help.
Thank you.
python python-3.x pynput
I have been trying all day to figure a way to automate the process of toggling on the new Windows 10 Mobile Hotspot setting, possibly using python 3, which you can find by navigating to Settings -> Network & Internet -> Mobile Hotspot -> The first toggle.
After spending almost the whole day, trying to find information such as, what registry key the toggle alters, to make it enable/disable the Mobile hotspot and googling to find articles that show some command prompt, power shell, etc. method to enable this this setting, I have been unsuccessful at finding a direct solution for automating the toggling of the toggle switch which either enables/ disables the Mobile Hotspot.
So I finally decided, to use a keypress module, pynput
in python 3, to automate the key presses I would need to make to go and toggle the setting. So using this module I wrote the following script:
def enableMobileHotspot():
keyboard = Controller()
#Open Settings
print("Opening Settings")
keyboard.press(Key.cmd) #Key.cmd = Windows Key
keyboard.press("i")
keyboard.release(Key.cmd)
keyboard.release("i")
time.sleep(3)
#Navigate to Network & Internet
print("Navigating to Network & Internet")
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.3)
keyboard.press(Key.right)
time.sleep(0.3)
keyboard.release(Key.right)
time.sleep(0.3)
keyboard.press(Key.right)
keyboard.release(Key.right)
time.sleep(0.3)
keyboard.press(Key.right)
keyboard.release(Key.right)
time.sleep(0.3)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(1)
#Navigate to Mobile hotspot
print("Navigating to Mobile Hotspot")
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.down)
keyboard.release(Key.down)
time.sleep(0.3)
keyboard.press(Key.enter)
keyboard.release(Key.enter)
time.sleep(15)
#Go To Toggle and Enable/ Disable Toggle
print("Navigating to Toggle and Enabling Mobile Hotspot")
keyboard.press(Key.tab)
keyboard.release(Key.tab)
time.sleep(0.3)
keyboard.press(Key.space)
keyboard.release(Key.space)
time.sleep(15)
# Close Setting Window
print("Closing Settings")
keyboard.press(Key.alt)
keyboard.press(Key.f4)
keyboard.release(Key.alt)
keyboard.release(Key.f4)
enableMobileHotspot()
The issue, I am facing with this script is that for some reason the command keyboard.press(Key.right)
just doesn't seem to work, for the Navigate to Network & Internet
process, as after executing the "tab" key press command, it simply stuck on the first settings option, i.e. System
. This is bad, because then the rest of the key press commands are occurring on the wrong settings.
I thought the issue may possibly be due to the key being pressed and released quite quickly, and therefore I tried to put some `time.sleep()' between the commands, but even that doesn't help.
I only need this script to ensure my laptop can automatically toggle the option, when its been restarted, as I use it to extend the WiFi at home.
If anybody has a solution as to why the right key command is not working I would really appreciate the help.
Thank you.
python python-3.x pynput
python python-3.x pynput
asked Nov 11 '18 at 23:16
SShah
487212
487212
have youu looked ctypes? docs.python.org/3/library/ctypes.html
– Jack Herer
Nov 12 '18 at 1:00
@JackHerer Thankyou for your reply, never heard of ctypes before if I am honest. Having looked at it, I don't get how I can use it, kindly please explain more, if you know of a way I can make use of it. Thanks
– SShah
Nov 12 '18 at 1:07
Ill be honest I have never needed to use ctypes for windows because i avoid windows like the plague!! I just know its very powerful, and in my opinion using windows mobile hotspot as a wifi extender is not the best way forward, why not get a free/cheap router that is an old ISP router and just make an extender from that? Sorry I cant be of much help other than that.
– Jack Herer
Nov 12 '18 at 1:21
@JackHerer Oh okay thanks, and its ok no problem, Thank you very much for all the support. I just need to extend the wifi temporarily therefore not bothered to purchase a cheap extender. Surprisingly, what I am finding, compared to a cheap repeater which I have used in the past, this mobile hotspot, seems more faster and stable.
– SShah
Nov 12 '18 at 9:39
add a comment |
have youu looked ctypes? docs.python.org/3/library/ctypes.html
– Jack Herer
Nov 12 '18 at 1:00
@JackHerer Thankyou for your reply, never heard of ctypes before if I am honest. Having looked at it, I don't get how I can use it, kindly please explain more, if you know of a way I can make use of it. Thanks
– SShah
Nov 12 '18 at 1:07
Ill be honest I have never needed to use ctypes for windows because i avoid windows like the plague!! I just know its very powerful, and in my opinion using windows mobile hotspot as a wifi extender is not the best way forward, why not get a free/cheap router that is an old ISP router and just make an extender from that? Sorry I cant be of much help other than that.
– Jack Herer
Nov 12 '18 at 1:21
@JackHerer Oh okay thanks, and its ok no problem, Thank you very much for all the support. I just need to extend the wifi temporarily therefore not bothered to purchase a cheap extender. Surprisingly, what I am finding, compared to a cheap repeater which I have used in the past, this mobile hotspot, seems more faster and stable.
– SShah
Nov 12 '18 at 9:39
have youu looked ctypes? docs.python.org/3/library/ctypes.html
– Jack Herer
Nov 12 '18 at 1:00
have youu looked ctypes? docs.python.org/3/library/ctypes.html
– Jack Herer
Nov 12 '18 at 1:00
@JackHerer Thankyou for your reply, never heard of ctypes before if I am honest. Having looked at it, I don't get how I can use it, kindly please explain more, if you know of a way I can make use of it. Thanks
– SShah
Nov 12 '18 at 1:07
@JackHerer Thankyou for your reply, never heard of ctypes before if I am honest. Having looked at it, I don't get how I can use it, kindly please explain more, if you know of a way I can make use of it. Thanks
– SShah
Nov 12 '18 at 1:07
Ill be honest I have never needed to use ctypes for windows because i avoid windows like the plague!! I just know its very powerful, and in my opinion using windows mobile hotspot as a wifi extender is not the best way forward, why not get a free/cheap router that is an old ISP router and just make an extender from that? Sorry I cant be of much help other than that.
– Jack Herer
Nov 12 '18 at 1:21
Ill be honest I have never needed to use ctypes for windows because i avoid windows like the plague!! I just know its very powerful, and in my opinion using windows mobile hotspot as a wifi extender is not the best way forward, why not get a free/cheap router that is an old ISP router and just make an extender from that? Sorry I cant be of much help other than that.
– Jack Herer
Nov 12 '18 at 1:21
@JackHerer Oh okay thanks, and its ok no problem, Thank you very much for all the support. I just need to extend the wifi temporarily therefore not bothered to purchase a cheap extender. Surprisingly, what I am finding, compared to a cheap repeater which I have used in the past, this mobile hotspot, seems more faster and stable.
– SShah
Nov 12 '18 at 9:39
@JackHerer Oh okay thanks, and its ok no problem, Thank you very much for all the support. I just need to extend the wifi temporarily therefore not bothered to purchase a cheap extender. Surprisingly, what I am finding, compared to a cheap repeater which I have used in the past, this mobile hotspot, seems more faster and stable.
– SShah
Nov 12 '18 at 9:39
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
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%2fstackoverflow.com%2fquestions%2f53254207%2fpynput-module-right-key-press-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2fstackoverflow.com%2fquestions%2f53254207%2fpynput-module-right-key-press-not-working%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
have youu looked ctypes? docs.python.org/3/library/ctypes.html
– Jack Herer
Nov 12 '18 at 1:00
@JackHerer Thankyou for your reply, never heard of ctypes before if I am honest. Having looked at it, I don't get how I can use it, kindly please explain more, if you know of a way I can make use of it. Thanks
– SShah
Nov 12 '18 at 1:07
Ill be honest I have never needed to use ctypes for windows because i avoid windows like the plague!! I just know its very powerful, and in my opinion using windows mobile hotspot as a wifi extender is not the best way forward, why not get a free/cheap router that is an old ISP router and just make an extender from that? Sorry I cant be of much help other than that.
– Jack Herer
Nov 12 '18 at 1:21
@JackHerer Oh okay thanks, and its ok no problem, Thank you very much for all the support. I just need to extend the wifi temporarily therefore not bothered to purchase a cheap extender. Surprisingly, what I am finding, compared to a cheap repeater which I have used in the past, this mobile hotspot, seems more faster and stable.
– SShah
Nov 12 '18 at 9:39