Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Photoshop shortcut toggle key


  • Please log in to reply
12 replies to this topic
ixaarii
  • Members
  • 14 posts
  • Last active: Nov 30 2012 04:55 PM
  • Joined: 16 Nov 2012
Hi. First of all this is my first post so I wanna thank everybody who worked on this for creating SUCH an amazingly powerful tool! I just found it today and am blown away by the possibilities.
I would like to ask a question:

My goal would be to transform the useless Windows key into a quick way for accessing the painter color picker in Photoshop, which has the shortcut: Alt+Shift+RMB, and while you're in it you pick the color, and after releasing the buttons you are left with the new color on your paint brush. So I was thinking this would be perfect for my first non-remap AutoHotkey use. Since the way I'd like this to work is as a toggle key (I pres Winkey, I pick the color, I press Winkey again to get out) I spent the last couple of hours trying to figure out how to create toggle code and all that, only to find out that the reason none of my attempts worked is that it doesn't work on a more basic layer. So, after debuggin I got to the conclusion that this is the simplest I can write the code and it still doesn't work:


LWin::Send {Alt Down}{Shift Down}{RButton Down}
LWin Up::Send {Alt Up}{Shift Up}{RButton Up}


So, what's happening is: the entering of the color picking mode works great. It's awesome that it goes in there because the color picker is kinda tricky and it can have additional keys mixed in so it's great not to have problems with too many keys. The problem is with the exiting. The exit code doesn't seem to work. I figured it's something with it figuring out the up state of the key, but even without that it doesn't work (tried putting the up states on a different key). It seems to me that somehow the Alt and the Shift get stuck down. I've tried multiple ways of reseting them. I've even tried a key to send a right click and an alt and a shift separately hoping that would reset, but nothing resets until I phisically press the alt and the shift and a right click. Is there someway I could enforce the reset of the states of those keys? Could this be a bug? I'm using Autohotkey v1.1.09.00, on Win 7, 64bit. Thank you very much for your help... and thank you again for the great software and for your time in reading this! It would be super great to have this working!!!

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Welcome to AHk forums.

In CS5+6 color picker is toggled by holding down/releasing ALT ( when brush is active ).
Then when the Left Mouse Button is clicked, the foreground color is updated.
Posted Image

Please let us know what version of PS are you using.

I can also test this in PS7 (CS1).

Posted Image

don't duplicate, iterate!


ixaarii
  • Members
  • 14 posts
  • Last active: Nov 30 2012 04:55 PM
  • Joined: 16 Nov 2012
Hi. Thanks for answering. I'm using CS6. I know that the normal color picker is just Alt, which is great, as it's just one key, but I do digital painting illustration/concept art and for that kind of stuff there's a much better color picker, called HUD color picker I believe, which is more like Painter, a hue triangle/color wheel, which unfortunately however has a complex multi key shortcut, and I would like to use autohotkey to make that simple, but whenever I try to do that it seems the keys are stuck.

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
>>transform the useless Windows key

Are you even allowed to write that in a windows forum ?? Posted Image

Here is code that is a simple toggle
flag = 0 ; the at-rest state is off, signified by the value 0
return
~Lwin:: ; with the ~ in place the user can still use 'win' as a modifier.
			 ; remove the ~ to prevent using the 'win' key for any other purpose.

flag := !flag ; the previous value is toggled between 1 & 0

tooltip %flag% ; just a diagnostic tool

if flag = 1 ; the flag state directs to start the task
{
tooltip %flag% ; replace with your desired commands
}
else	 ; the flag state directs to end the task
{
tooltip %flag% ; replace with your desired commands
}
return


ixaarii
  • Members
  • 14 posts
  • Last active: Nov 30 2012 04:55 PM
  • Joined: 16 Nov 2012

>>transform the useless Windows key
Are you even allowed to write that in a windows forum ?? Posted Image


:))))))))))))))

Thank you so much for your toggle code! It's brilliant! Also thank you for making it so very clear, and the tooltip use for feedback is just pure genius! Thank you so very much! that's priceless! One question about the initialization of the variable... when does that happen? Is it run before anything else? Can any line like that outside of a condition catcher function as an initialization moment?

In case it's useful to anybody in creating a similar photoshop hotkey for the HUD color picker or something similar this is how I used your code to make it work:


flag = 1 ; the at-rest state is off, signified by the value 0
return
*Lwin::
flag := !flag ; the previous value is toggled between 1 & 0
if flag = 1 ; the flag state directs to start the task
{
Send {Alt Up}{Shift Up}{RButton Up}
}
else  ; the flag state directs to end the task
{
Send {Alt Down}{Shift Down}{RButton Down}
}
return
Thank you very much for your help! I can't believe how powerful Autohotkey is. My fingers were getting twisted & broken trying to press all those keys at a time (combined with a bonus of space for an extra freeze option for the color picking to move to the color wheel without chaninging the luminosity). This is soooooooooooo briilliant! Thaaank youu Leef_me, thank you everybody on the forums, and of course big thank you to the developers!

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
>>One question about the initialization of the variable... when does that happen?
>>Is it run before anything else?

Please go to this part of the docs http://l.autohotkey....ocs/Scripts.htm
and read (at least) these sections

Introduction
The Top of the Script (the Auto-execute Section)


>>Can any line like that outside of a condition catcher function as an initialization moment?

I don't quite understand your question.
We aren't quite speaking the same language/lingo.

Please try again with your question.

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Couple of things to note. 1st off, the toggle script can be significantly reduced.
Try this example to see what I mean ( repeatedly press Left Win Key ;) ):
*Lwin::MsgBox % "{Alt " (st:=(flag:=!flag) ? "Up" : "Down") "}{Shift " st "}{RButton " st "}"
To make it work in PS, replace MsgBox % with Send %.

Next, regarding Send, in many cases with PhotoShop you will be using the mouse and other things while sending this command.
Send, can interrupt your interaction with PhotoShop.
To workaround this consider using ControlSend with either the name/class of the control or no Control name at all ( Sends to PS's top level window ).
See ControlSend for further details.

Posted Image

don't duplicate, iterate!


Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
@ TLM
I can agree about your suggested use of ControlSend

OTOH, I disagree about your need to "significantly reduce.." the size of the toggle.

ixaarii is a new user, and IMO would benefit more from documented code that is easier to understand.

I have no doubt that your code works as well as the one I posted.
however, it requires some level of experience to 'decode' the contents.

The savings in script space cannot seriously be an issue, and saving in time is likewise insignficant.

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Just offering an alternative, I never suggested it was a "need". The use of the ternary condition is documented in the manual under operators.

? : Ternary operator [v1.0.46+]. This operator is a shorthand replacement for the if-else statement. It evaluates the condition on its left side to determine which of its two branches should become its final result. For example, var := x>y ? 2 : 3 stores 2 in Var if x is greater than y; otherwise it stores 3. To enhance performance, only the winning branch is evaluated (see short-circuit evaluation). Note: For compatibility reasons, the question mark must have at least one space on both sides (this may be resolved in a future version).


One could argue that the using the term "flag" in this instance is not the best advice to give a new user.
Flags are typically members of a defined data structs and tend to have a broader set of choices than just true or false.
"i" or "st" or ever "toggle" are much better terms in simple 1 or 0 circumstances such as this.

Posted Image

don't duplicate, iterate!


ixaarii
  • Members
  • 14 posts
  • Last active: Nov 30 2012 04:55 PM
  • Joined: 16 Nov 2012

>>Can any line like that outside of a condition catcher function as an initialization moment?
I don't quite understand your question.
We aren't quite speaking the same language/lingo.
Please try again with your question.

Because in various examples there was an initialization before the actual code that catches the keys, I had first assumed that any line of code not prefaced by some kind of key cendition (like say r:: to catch r keypresses) will get run as initialization, but now, if I get it right, I think the way it works has in fact to do with the top of the script code, until the first "return" (i'm assuming there's an implicit return after something like r::m, thus ending the init section. I think it would have helped if the default/example script had a section marked with comments as initialization area.

Couple of things to note. 1st off, the toggle script can be significantly reduced.
Try this example to see what I mean ( repeatedly press Left Win Key Posted Image ):
*Lwin::MsgBox % "{Alt " (st:=(flag:=!flag) ? "Up" : "Down") "}{Shift " st "}{RButton " st "}"
To make it work in PS, replace MsgBox % with Send %.

Next, regarding Send, in many cases with PhotoShop you will be using the mouse and other things while sending this command.
Send, can interrupt your interaction with PhotoShop.
To workaround this consider using ControlSend with either the name/class of the control or no Control name at all ( Sends to PS's top level window ).
See ControlSend for further details.

Cool code! About ControlSend I did read there but I'm afraid didn't particularly get what it does different... targeting a speciffic window?

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
Your current understand is almost perfect. The implicit return is before the first hotkey/string.
To make the script more readable, I insert a literal 'return' command.

>>...I had first assumed that any line of code not prefaced by some kind of key cendition
>>(like say r:: to catch r keypresses) will get run as initialization,

pardon me, but what is "cendition" ? I cannot find a definition.

ixaarii
  • Members
  • 14 posts
  • Last active: Nov 30 2012 04:55 PM
  • Joined: 16 Nov 2012
Sorry, typo. I meant a condition. Like r:: catches the condition if "if key r was pressed then do ... ".
But I think I understand now. Thank you!

markb
  • Members
  • 17 posts
  • Last active: Dec 10 2017 03:25 AM
  • Joined: 03 Dec 2012
Sounds like you resolved it. I use this code to bring up the HUD. (I use the '3' key)
It pops up while you are holding your key down. Still have to use 'space' to change hue.
3::
    {
    send {alt down}{shift down}
    mouseclick, right,,, 1, 0, d
    Loop
	 {
	 sleep, 10
	 GetKeyState, state, 3, p
	 if state = u
	 break
	 }
    mouseclick, right,,, 1, 0, u
    send {alt up}{shift up}
    return
    }