So I do: if keyboard.is_pressed("shift + +"):
And it gives me an error.
I need it to be in the same 'command'.
Please don't post this as an answer:
if keyboard.is_pressed("shift") and keyboard.is_pressed("+"):
Thanks in advance!
The reason it doesn't work is due to how keyboard parses this "hotkey" string. This is from the source code:
for step in _re.split(r',\s?', hotkey):
keys = _re.split(r'\s?\+\s?', step)
It just splits on "+" so you end up with ["shift", "", ""], which has two empty strings, hence an error.
You can do it like this:
if keyboard.is_pressed([sc1, sc2]):
where sc1 and sc2 are the "scan codes" of the keys you want.
For example, it might look like this:
if keyboard.is_pressed([56, 89]):
To find the scan codes, use a script like this:
import keyboard
while True:
print(keyboard.read_event().scan_code)
Just run that script and press the keys you are interested in to see their scan codes get printed. Use these for sc1 and sc2 in the first code block in this answer.
From reading the source code, this should also work:
if keyboard.is_pressed(["shift", "+"]):
but it doesn't work for me. Maybe it will work for you.
Warning: This keyboard module will sometimes have different scan_codes for different keyboards and different operating systems.
Related
Ok, so I get two errors whenever I try to run this script: but before I get ahead of myself: lets get to my objective.
create two joint chains, names are unimportant: but essentially I know that you can use brackets to list and isolate joint chains with matching children names. Instead my script seems to be ignoring the brackets and giving me the error anyways. I've tried every different flag for list relatives: but all that seems to do is change the error to something else.
I know that if this script was properly working it would only work on one joint chain because of the hardcoded names: but the script I'm pulling it from has name prefexes tied to the GUI to avoid hardcoding and allow adaptive naming: I'm only using the hardcoded as an example for this script. My complaint is this script doesn't work on ANY joint chain because I keep getting the error "more than one object matches name."
To run the script,save the following code as a .py in your maya documents script folder, restart your copy of maya, then open a new python tab and run the first three lines of code above import maya.cmds
'''
import exampleScriptTemplate
reload (exampleScriptTemplate)
exampleScriptTemplate.gui()
'''
import maya.cmds as cmds
if cmds.window("buildWin", exists =True):
cmds.deleteUI("buildWin", window = True)
myWindow = cmds.window("buildWin",t='DS_pvFinder',rtf=1,w=100, h=100, toolbox=True)
column = cmds.columnLayout(adj=True)
def gui(*args):
cmds.columnLayout()
cmds.button(w=300,label='build placement curve',c=printMultiple)
cmds.showWindow(myWindow)
def printMultiple(*args):
root = cmds.ls(sl=True)[0]
child = cmds.listRelatives(root,ad=1,f=True,children=True,type='joint')
child.append(root)
child.reverse()
limbJnt = child
print (child)
armroot = []
for j in limbJnt:
wstJnt = cmds.rename(child[3], 'wrist_BIND')
elbJnt = cmds.rename(child[2], 'elbow_BIND')
sdrJnt = cmds.rename(child[1], 'shoulder_BIND')
clvJnt = cmds.rename(child[0], 'clavicle_BIND')
armroot.append(j)
return armroot
I know I'm in the right ballpark. I just need to know how to properly use the brackets to store the list of what i'm selecting instead of searching all of worldspace and breaking.
Thank you for your help
The code you provided is incomplete, no window is opening, so I tried only the printMultiple function which causes a Error: No object matches name in my case.
Your code cannot work like this since you mix hardcoded names with a loop which does nothing. I suppose your main problem is the order of your renamings. The child array contains absolute names like:
[u'joint1', u'|joint1|joint2', u'|joint1|joint2|joint3']
If you now rename child[0] to 'clavicle_BIND', all the remaining elements in the list become invalid because their real names in the scene now look like this:
[u'clavicle_BIND', u'|clavicle_BIND|joint2', u'|clavicle_BIND|joint2|joint3']
What results in an error at the second rename line. Inverting the order sovles this problem, first rename the leaf node, then the ones above.
I have been using a virtual keyboard that uses ctypes in Python 3.3 for a while, and I can't get it to do Ctrl-Shift-Home, among other triple-key expressions, like Ctrl-Alt-Delete. The expression Ctrl-Shift-Home selects the text starting at the cursor going back to the beginning of the text---which works when I press the expression manually, but I cannot get my code to do it.
My code is essentially the same as the code from this stackoverflow answer, and then to do the expression I could do something like
def Ctrl_Shift_Home():
PressKey(0x11) # Ctrl
PressKey(0x10) # Shift
PressKey(0x24) # Home
time.sleep(0.1)
ReleaseKey(0x24)
ReleaseKey(0x10)
ReleaseKey(0x11)
But the above does not select any text. Is this an issue with the code itself, or an issue with triple-key expressions, or is selecting text just not allowed using keyboard events?
Any answers or alternatives would be appreciated! Thank you!
Using Python 3.4.2
I'm working on a quiz system using python. Though it hasn't been efficient, it has been working till now.
Currently, I have a certain user log in, take a quiz, and the results of the quiz get saved to a file for that users results. I tried adding in so that it also saves to a file specific to the subject being tested, but that's where the problem appears.
user_score = str(user_score)
user_score_percentage_str = str(user_score_percentage)
q = open('user '+(username)+' results.txt','a')
q.write(test_choice)
q.write('\n')
q.write(user_score+'/5')
q.write('\n')
q.write(user_score_percentage_str)
q.write('\n')
q.write(user_grade)
q.write('\n')
q.close()
fgh = open(test_choice+'results.txt' ,'a')
fgh.write(username)
fgh.write('\n')
fgh.write(user_score_percentage_str)
fgh.write('\n')
fgh.close
print("Your result is: ", user_score , "which is ", user_score_percentage,"%")
print("Meaning your grade is: ", user_grade)
Start()
Everything for q works (this saves to the results of the user)
However, once it comes to the fgh, the thing doesn't work at all. I receive no error message, however when I go the file, nothing ever appears.
The variables used in the fgh section:
test_choice this should work, since it worked for the q section
username, this should also work since it worked for the q section
user_score_percentage_str and this, once more, should work since it worked for the q section.
I receive no errors, and the code itself doesn't break as it then correctly goes on to print out the last lines and return to Start().
What I would have expected in the file is to be something like:
TestUsername123
80
But instead, the file in question remains blank, leading me to believe there must be something I'm missing regarding working the file.
(Note, I know this code is unefficient, but except this one part it all worked.)
Also, apologies if there's problem with my question layout, it's my first time asking a question.
And as MooingRawr kindly pointed out, it was indeed me being blind.
I forgot the () after the fgh.close.
Problem solved.
from pywinauto import application
app=application.Application()
3. app.connect(title_re = "/Zero Hedge$/")
4. app.connect(title_re = "/| Zero Hedge/")
I want to get a window of Chrome like this: http://www.zerohedge.com/news/2016-02-18/markets-ignore-fundamentals-and-chase-headlines-because-they-are-dying
As you see when you visit the website, the website title contains "| Zero Hedge" in the last part of it or only "Zero Hedge" contained.
However, I still get a WindowNotFoundError raised in no matter line 3 or line 4. Why the Regular Expression didn't work?
Thank you for all your help!
try this to get a list of all of your windows/titles:
from pywinauto import findwindows
print findwindows.find_windows(title_re=".*")
That should get you a list of all windows and then build your regex based off the results.
Motivation: I was going around assigning parameters read in from a config file to variables in a function like so:
john = my_quest
terry = my_fav_color
eric = airspeed
ni = swallow_type
...
when I realized this was going to be a lot of parameters to pass. I thus decided I'd put these parameters in a nice dictionary, grail, e.g. grail['my_quest'] so that the only thing I needed to pass to the function was grail.
Question: Is there a simple way in Sublime (or Notepad++, Spyder, Pycharm, etc.) to paste grails['variable'] around those variables in one step, instead of needing to paste the front and back seperately? (I know about multiple cursors in Sublime, that does help, but I'd love to find a "highlight-variable-and-hit-ctrl-meta-shift-\" and it's done.)
Based on examples you provided, this is a simple task solvable using standard regex find/replace.
So in Notepad++, record this macro (for recording control examine Macro menu):
Press Ctrl+H to open Find/Replace dialog
Find what: = (.*)$
Replace with: = grail['\1']
Choose Regular Expression and press Replace All
If you finish recording the macro and you choose to save it, shortcut key is requested. Assign your favorite ctrl-meta-shift-\ and you are done.