Is this even possible with AHK Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
PaulySkating

Is this even possible with AHK

17 Dec 2017, 02:00

I am planning for a script and I would like to use both

LBUTTON::
and
~LBUTTON::

Both in the same script but they will do different things. AHK throws a duplicate error.

My question is two things;;

a- IS there a way (maybe with the suspend on command?) to use both?

b- IF not, what are my options?

My goal is that sometimes in my program when I press the left mouse button I want to continue as usual but display a message. Other times, I want to display the message but not allow the button to be clicked.

I am not looking to disable buttons or using other methods for now. I want to know if this can be done using LBUTTON and ~LBUTTON in one script or is there another way to detect this using a different method that would give a duplicate error?

Thank you everyone for any insight in this situation.
Rohwedder
Posts: 1076
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Is this even possible with AHK

17 Dec 2017, 04:36

Hallo,
switch with F4:

Code: [Select all] [Download] GeSHi © Codebox Plus

F4::only_message:=!only_message                    
~LButton::ToolTip, LButton + message
#If only_message
LButton::ToolTip, only message
#If
SirRFI
Posts: 403
Joined: 25 Nov 2015, 16:52

Re: Is this even possible with AHK

17 Dec 2017, 04:57

As mentioned above - You can use #If condition to make same hotkey work in various situations.
Use [code=autohotkey] forum tag to share your code.
Click on (Accept this answer) on top-right part of the post if it has answered your question / solved your problem.
PaulySkating

Re: Is this even possible with AHK

17 Dec 2017, 06:00

Rohwedder wrote:Hallo,
switch with F4:

Code: [Select all] [Download] GeSHi © Codebox Plus

F4::only_message:=!only_message                    
~LButton::ToolTip, LButton + message
#If only_message
LButton::ToolTip, only message
#If


thank You,

I tested and found that the #if is executed once when the script loads. This means, if I have a condition

Code: [Select all] [Download] GeSHi © Codebox Plus

#if (rohwedder = 1)
~LButton::ToolTip, LButton + message
#if (rohwedder = 2)
LButton::ToolTip, only message
#If


The script will go by what the value of rohwedder was when it loaded. Your hotkey example worked well, but in my case I cannot use a hotkey.

Is there an #if that keeps checking? I tried throwing it into a timer but that did not work.

One last question, do you know if the #if can check for many things before activating the LBUTTON::

For example

1 #if (rohwedder = 1)
2 go to this
3 then that
4 and if such and such = true
5 LBUTTON::
6 some action

I was going to do all those items on line 2 3 and 4 outside of the #if and then set some variable like rohwedder = 1. My thing is I am open to ideas and flexible, a little guidance goes a long way.

Thank you
Gilaade
Posts: 5
Joined: 06 Jun 2017, 07:04
Facebook: Gilaad Elstein
Google: Gilaad Elstein
GitHub: Gilaad

Re: Is this even possible with AHK

17 Dec 2017, 07:35

Why not evaluate the if inside the actual hotkey? Eg

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Rohwedder
Posts: 1076
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Is this even possible with AHK  Topic is solved

17 Dec 2017, 16:29

Hallo,
an #If [, Expression ] keeps checking all the time, not only when the script is loaded!
Try:

Code: [Select all] [Download] GeSHi © Codebox Plus

~LButton::ToolTip, LButton + message
#If Mod(A_TickCount,2000) < 1000
LButton::ToolTip, only message
#If
Every second the #If [, Expression ] toggles between ~LButton :: and LButton ::
PaulySkating

Re: Is this even possible with AHK

17 Dec 2017, 17:20

Rohwedder wrote:Hallo,
an #If [, Expression ] keeps checking all the time, not only when the script is loaded!
Try:

Code: [Select all] [Download] GeSHi © Codebox Plus

~LButton::ToolTip, LButton + message
#If Mod(A_TickCount,2000) < 1000
LButton::ToolTip, only message
#If
Every second the #If [, Expression ] toggles between ~LButton :: and LButton ::


Thank you, can you explain why this code fails to switch?

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Rohwedder
Posts: 1076
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Is this even possible with AHK

18 Dec 2017, 01:36

Hallo,
the update (= Period) of the timer was every second, so the 5 second sleep within the timer could never was ended.
Try:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

PaulySkating

Re: Is this even possible with AHK

19 Dec 2017, 14:56

Rohwedder wrote:Hallo,
the update (= Period) of the timer was every second, so the 5 second sleep within the timer could never was ended.
Try:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


I would like to thank you from the bottom of my heart. You helped a lot and everything works now. Thanks!!!

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, TAC109 and 36 guests