0
votes

I use an on-screen keyboard to type math notes. I defined some of its buttons as hotkey combos, effectively creating touch-screen macros like this:

^!2::send tan
^!3::send cos
^!4::send, sin 
^!5::send csc
^!6::send sec
^!0::send cot

I need to toggle these hotkeys ON when (and only when) clicking the left mouse button, to make sure the correct macros on the touch screen keyboard are sent (and my normal keys on the keyboard are active at any other time.)

The following code worked, except for one macro that toggles device management software that I use (DevManView). That software toggle only works reliably when the script is not suspended.

Suspend, on
~LButton::suspend, off
~lbutton up::
sleep, 50
suspend, on
return

So I am looking for another way to toggle these macros without suspending the entire script. It will also teach me a thing or two about loop parsing.

keys:="^!,¢^!\¢^!1¢^!8¢^!`¢^!2¢^!3¢^!4¢^!5¢^!6¢^!0¢^!.¢@¢^@¢^#¢^$¢^+5¢^^¢^*¢^`"
Loop,Parse,keys, ¢ ;create the hotkeys
            Hotkey,$%A_loopField%,MEOK_MACROS
Loop,Parse,keys ;turn them off
        Hotkey,$%A_loopField%,Off
~LButton::
sleep, 50
    Loop,Parse,keys ;toggle hotkeys
            Hotkey,$%A_loopField%,Toggle
return
MEOK_MACROS:
    Send % InStr(keys,SubStr(A_ThisHotkey,0))
return

I want to put all the control+alt+(key) & control+(key) macros I created into one string, then toggle them on and off with ~LButton. Can you point out where I went wrong here?

2

2 Answers

0
votes

It looks like you have a good understanding of loops. The only errors I find are specifying the delimiter on your second and third loops. See below:

keys:="^!,¢^!\¢^!1¢^!8¢^!`¢^!2¢^!3¢^!4¢^!5¢^!6¢^!0¢^!.¢@¢^@¢^#¢^$¢^+5¢^^¢^*¢^`"
Loop,Parse,keys, ¢ ;create the hotkeys
        Hotkey,$%A_loopField%,MEOK_MACROS
Loop,Parse,keys, ¢ ;turn them off ***MISSING DELIMITER
        Hotkey,$%A_loopField%,Off
~LButton::
sleep, 50
    Loop,Parse,keys, ¢ ;toggle hotkeys  ***MISSING DELIMITER
            Hotkey,$%A_loopField%,Toggle
return
MEOK_MACROS:
    Send % InStr(keys,SubStr(A_ThisHotkey,0))
return
0
votes

You can use the mouse click as part of the hotkey, then you do not need to toggle anything on or off.

~LButton & c::
    Run Notepad
    Return

or from your example

~LButton & 2::send tan

The ~ will leave the Left mouse button working normally and only trigger the hotkey when it is down and the second button is pushed at the same time.