0

I am trying to map a key to toggle between two different shortcuts. The purpose is to easily switch between desktops in Windows 10 (instead of having to press three buttons)

What I am trying is:

toggle      := false
½:: Toggle = false ? ( ^#Right, Toggle := true ) : ( ^#Left, Toggle := false )

She script runs without errors, but it does not work.

Can someone give me a hint?

Nicolai Lissau
  • 7,298
  • 5
  • 43
  • 57

2 Answers2

1

It should be send ^#Right, but you cannot put extra commands into the ternary operator. You may only specify a value to be stored into toggle (as shown here).

Toggle = false ? ... has to be Toggle := false ? ..., for the right-hand side is an expression, not a string.

Try

%::
    toggle := !toggle
    if(toggle)
        send ^#{Right}
    else
        send ^#{Left}
return

I personally can't think of a more compact way of doing it, which you obviously want to achieve.

Community
  • 1
  • 1
phil294
  • 10,038
  • 8
  • 65
  • 98
  • Thank you for your answer! Unfortunately, it's not working for me. And if i go into a notepad, then it toggles between writing out "eft" and "ight" (without the quotes of course)? Very strange. From the docs it says that Right and Left are commands, but seems more like AutoHotKey is interpreting the R and L only? – Nicolai Lissau Aug 17 '15 at 11:19
  • 1
    ah well it has to be `send ^#{Right}`, of course. i edited my post – phil294 Aug 17 '15 at 14:18
  • Thank you! I tried with the brackets around all of the commands `{^#Right} `. Thank you Blauhirm! This makes working on the desktops so much easier – Nicolai Lissau Aug 17 '15 at 14:25
1

If you want to toggle with more then two [Keyboard Shortcuts] toggle's,

you can use this AHK code.

Example1.ahk

; [+ = Shift] [! = Alt] [^ = Ctrl] [# = Win] 
#SingleInstance ignore
a := 1 

; If you want to toggle with more the two toggle's you can use this code.
;a = 1   => send {^#Right}
;a = 2   => send {^#Left}
;a = 3   => send {????}

;click the f1 key to toggle 
f1::
if (a=1)
{
Menu, Tray, Icon,c:\icons\32x32\icon1.ico,1,1 ; change tray icon
send {^#Right}
a := 2
}else{

if (a=2)
{
Menu, Tray, Icon,c:\icons\32x32\icon2.ico,1,1 ; change tray icon
send {^#Left}
a := 3
}else{

if (a=3)
{
Menu, Tray, Icon,c:\icons\32x32\icon3.ico,1,1 ; change tray icon
;send {????}
a := 1
}}}
return

esc::exitapp
stevecody
  • 658
  • 1
  • 6
  • 18