"Press any key"
Richard Haseltine
Posts: 100,747
Is there a way to check if any key is pressed? There are the globals to check shift and ctrl, DzApp can check the modifiers generally and for a particular key or combo, but I don't see a method to ask if any key has been pressed (returning a string, presumably). I want to be able to stop a script with any key press, rather than having to ask for one in particular. dzApp also has the mouseEvent() signal, but there doesn't seem to be a keyboardEvent() to match
Post edited by Richard Haseltine on
Comments
Take a look at the Background Progress sample. It doesn't show how to handle "any" key, but it does show how to handle a specific key (e.g., "Esc"); many of the other script samples show how to dynamically handle the key sequence bound to a given action. Handling "any" key would require deeper exposure of the event stack/loop than we are inclined/willing to provide.
-Rob
OK, thank you, I'll do it as an specific key then.
Richard you can use the App.isKeyDown (number [Qt::Key value]) instead and do your work! I have modified Rob's Background Progress script and it seems to work. The problem is that we don't know the Qt::Key values of the keyboard but thankfully DAZ uses the same key codes as Microsoft. A little digging to the net and here are the codes: Keys Enum. Now what I have done to the Background Progress script:
First of all:
Declare some variables for the function:
I place it under the
// Start the progress
comment.
Next I set two arrays under my preview "bFinished" line, with the keys and their index numbers (Long code follows:)
The next code goes in the if(bCancellable) bracket area of the script and replace the code of Rob:
as you can see I have a loop running 193 times, as the length of my arrays.
I put an if command with App.isKeyDown method and I kept the App.isKeySequenceDown( "Esc" ) of Rob, paired with logical "or", so if anything goes wrong the user still can end with "Esc"!
I print out the Key pressed name (I took it from the second array). You can use the value as you want.
I set the bFinished boolean to true and move the break command to the first loop.
If I had Rob's permission I could paste the whole code of my modified Background Progress script here or maybe upload the script.
Use this code and you will be amazed by the resault!
Bye ...
Yeah, I thought of iterating over a list of keys, and in fact it would be OK for this application (so thank you for generating the list), but it wouldn't work as well when the process to be interrupted was more intensive and taking the time out to scan that array might well be an unacceptable overhead.
Isn't there a way to simply test that
App.isKeyDown()
isn't a null set? Or a binary (rather than index) 0? Then the keymap in question would only matter for the N + " key is pressed" routine, if at all.App.isKeyDown()
has to have a parameter, specifying a key - otherwise yes (in fact that was my thought, get the keyboard state and continue while it's empty/null).@Richard Keep an eye on the Change Log. 4.11.0.263 will include a change to DzApp::isKeyDown() that allows a negative number (which is -1 by default as of said build) to mean "any key". It will also include a change to DzApp::isKeySequenceDown() that allows (case-insensetive) "Any" (the default as of said build) to mean the same.
-Rob
Ah, good - thank you.