Reputation: 1
i made a little tool to bind the ctrl+win+right arrow to a key in this code its F2 the probleme is when i try to use pyinstaller to make it an executable for my friends who wanted this tool , when i try to open the exe it said failed to execute the script . but it works properly with python idle the code is :
from pynput.keyboard import Key , Controller
keyboard = Controller()
i=2
import keyboard
import time
def waitUntil(): #defines function
wU = True
while wU == True:
if not keyboard.is_pressed("F2"): #checks the condition
wU = False
else:
wU = True
while i == 2 :
if keyboard.is_pressed("F2") :
waitUntil()
keyboard.press("Ctrl+cmd+Right")
keyboard.release("Ctrl+cmd+Right")```
Upvotes: 0
Views: 86
Reputation: 739
It's hard to help here because ultimately Controller doesn't have an method called "is_pressed()".
Clean up your code as such:
from pynput.keyboard import Controller
keyboard = Controller()
def waitUntil(): #defines function
wU = True
while wU == True:
if not keyboard.is_pressed("F2"): #checks the condition
wU = False
else:
wU = True
while True :
if keyboard.is_pressed("F2") :
waitUntil()
keyboard.press("Ctrl+cmd+Right")
keyboard.release("Ctrl+cmd+Right")
and you should get the following error when run:
Traceback (most recent call last):
File "/home/oubnouquestion.py", line 14, in <module>
if keyboard.is_pressed("F2") :
AttributeError: 'Controller' object has no attribute 'is_pressed'
At least this is what I get on Linux with the latest version of pynput. Thus, it broken even before I get to Pyinstaller. Are you sure this works in Idle?
Upvotes: 1