Jump to content
Macro Express Forums

Hold the right arrow key down?


Recommended Posts

I don't think that will work. I believe it would need to be done in one macro. You would need to test this but i think the <CTRLD> would end when the macro finished running. What did your testing tell you? I think you might need one macro to do the keystrokes you described and another to stop it. Maybe by having a loop in the first one that checks for a registry value. And the second macro would change that registry value causing the first one to abort the loop. But you would need to test it. I'm only speculating. 

Link to comment
Share on other sites

How would you activate each macro? It may be possible to do a <CTRLD> in one macro and <CTRLU> in another but if your macros used keys for activation then it would not work. You may not be able to activate the second macro if the control key was down.

I do not know if it will work but here is something to try:

Ctrl / Right arrow keys down

Text Type (Simulate Keystrokes): <CTRLD>
Text Type (Simulate Keystrokes): <KEYD:VK_RIGHT>

Ctrl / Right arrow keys up

Text Type (Simulate Keystrokes): <CTRLU>
Text Type (Simulate Keystrokes): <KEYU:VK_RIGHT>

 

Link to comment
Share on other sites

This kind of works. Assign a key to start the following macro. Once it's running, hold down the Ctrl key for about half a second to stop it. (I also tested with Alt instead of Ctrl, but there were too many side effects.)

 

Repeat Until %1% Equals "0" // Repeat forever
  Get Key State "Control" into %IsCtrlPressed%
  If Variable %IsCtrlPressed% Equals "TRUE"
    Beep
    Repeat Exit
  Else
    Text Type (Simulate Keystrokes): <CONTROL><ARROW RIGHT>
    Delay: 100 milliseconds  // Optional delay. You may not need it. 
  End If
End Repeat
<REPEAT UNTIL Variable="%1%" Condition="\x00" Value="0" _COMMENT="Repeat forever"/>
<GET KEY STATE Key="Control" Dest="%IsCtrlPressed%"/>
<IF VARIABLE Variable="%IsCtrlPressed%" Condition="\x00" Value="TRUE" IgnoreCase="FALSE"/>
<BEEP/>
<REPEAT EXIT/>
<ELSE/>
<TEXT TYPE Action="0" Text="<CONTROL><ARROW RIGHT>"/>
<DELAY Flags="\x02" Time="100" _COMMENT="Optional delay. You may not need it. "/>
<END IF/>
<END REPEAT/>

 

Link to comment
Share on other sites

20 hours ago, Tee Hiett said:

I would like to build 2 macros, one to hold the control key and the right arrow key down and another to release the control key and the right arrow key.

Thanks,

Tee

While there may be workarounds (see above), it might be better to do as suggested and to combine into one macro. I have several that mes around with toggling function keys

It might help if you said what you want to achieve.

Link to comment
Share on other sites

I've improved my script a bit. The main limitation: only eight choices for keys to halt the macro, which are set via the "Get Key State" statement:

Control

Shift

Alt

Caps Lock

Scroll Lock

Num Lock

Left Window key

Right Window key

 

Pressing Alt can easily switch focus to the menubar or ribbon, so not a good choice. Control seems innocuous. Shift might be fine, as well. I haven't tried any of the others due to possible side effects, but some could be fine:

I managed to eliminate the infinite loop controlled with an IF statement. Instead, I used Repeat Until with a Boolean variable, i.e., its value is either TRUE or FALSE. The new version seems to stop more quickly when the Ctrl key is pressed. To reduce the time needed to hold down the Ctrl key even more, reduce the length of the delay, or eliminate it if you can.

Repeat Until %IsCtrlPressed% Equals "TRUE"
  Get Key State "Control" into %IsCtrlPressed%
  Text Type (Simulate Keystrokes): <CONTROL><ARROW RIGHT>
  Delay: 100 milliseconds // Optional delay. You may not need it. 
End Repeat

<REPEAT UNTIL Variable="%IsCtrlPressed%" Condition="\x00" Value="TRUE"/>
<GET KEY STATE Key="Control" Dest="%IsCtrlPressed%"/>
<TEXT TYPE Action="0" Text="<CONTROL><ARROW RIGHT>"/>
<DELAY Flags="\x02" Time="100" _COMMENT="Optional delay. You may not need it. "/>
<END REPEAT/>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...