SC How to sense Shift etc in a loop?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Papoulka
Posts: 455
Joined: 13 Jul 2013 23:41

SC How to sense Shift etc in a loop?

Post by Papoulka »

My script needs to wait at one point until Shift is released. I'm trying:

Code: Select all

while (<get "shift">!=0) {$xxx=0;}
but this never detects the absence of the Shift key, so it's an endless loop.

There is the same problem if I wait for the Shift (or Alt or Ctl etc) key to be pressed:

Code: Select all

while (<get "shift">==0) {$xxx=0;}
There seems to be a problem with the detection code when it's used in a tight loop like this, in real time. The detection does work under "Try Script", and in a non-loop situation. Not posted as a bug because I might be misunderstanding the intent of the command.

Also a maybe-but-not-sure bug: I can't break from this script loop. The "Esc" key has no effect. Neither does mild swearing. I have to kill XY.

FluxTorpedoe
Posts: 906
Joined: 05 Oct 2011 13:15

Re: SC How to sense Shift etc in a loop?

Post by FluxTorpedoe »

Hi’
Adding a wait should give the script enough “headroom” to react, even to the ESC key (only tried in "Run script…" though), e.g.:

Code: Select all

while (<get "shift">==0) {$xxx=0; wait 50;} msg "Ok";

Papoulka
Posts: 455
Joined: 13 Jul 2013 23:41

Re: SC How to sense Shift etc in a loop?

Post by Papoulka »

Thanx Flux. That solved my current problem. And of course with the 'wait' I don't need the dummy variable assignment.

I didn't realize that a single instance of XY can continue to be used while it's running a script. E.g. with this looping:

Code: Select all

while (<get "shift">==0) {wait 50;}
 msg "Done";
I can rename files in the current pane, etc.

Having a more complex script running seems to interfere with keyboard input - maybe too much for the technique to be useful. But it's interesting.

klownboy
Posts: 4477
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440

Re: SC How to sense Shift etc in a loop?

Post by klownboy »

Hey Papoulka, that's very interesting - actually using a modifier key to initiate an action. :appl:

Edit: I shouldn't have said "initiate" an action above. I've used it in menus to perform alternate actions based on whether a modifier is down, but here you show an example of how you might incorporate it in a non-menu type script.

Post Reply