我一直在努力寻找一种方法来自动切换新的Windows 10移动热点设置,可能使用python 3,您可以通过导航到“设置”->“网络和Internet”->“移动热点”来找到该方法->第一次切换。
花了几乎一整天的时间后,尝试查找信息,例如切换开关更改了哪些注册表项,以使其启用/禁用移动热点,并使用Google搜索来查找显示一些命令提示符,Power Shell等方法的文章。要启用此设置,我一直未能找到一种直接解决方案来自动切换切换开关(启用/禁用移动热点)。
因此,我最终决定在python 3中使用按键模块pynput
来自动执行按键操作,以切换设置。因此,使用此模块,我编写了以下脚本:
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()
此脚本面临的问题是,由于某种原因,keyboard.press(Key.right)
的命令Navigate to Network & Internet
似乎不起作用,就像执行“ tab”键后一样命令,它只是停留在第一个设置选项上,即System
。这很不好,因为其余的按键命令都是在错误的设置下发生的。
我认为问题可能是由于快速按下并释放了按键,因此我试图在命令之间放置一些“ time.sleep()”,但这仍然无济于事。
我只需要使用此脚本来确保笔记本电脑在重新启动该选项时可以自动切换该选项,因为我使用它可以扩展WiFi。
如果有人对右键盘命令为何不起作用有解决方案,我将非常感谢您的帮助。
谢谢。