Is this even possible with AHK

Get help with using AutoHotkey (v1.1 and older) 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: 7623
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

F4::only_message:=!only_message                    
~LButton::ToolTip, LButton + message
#If only_message
LButton::ToolTip, only message
#If
SirRFI
Posts: 404
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: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) 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

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

#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
Contact:

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

A::
If condition
     Msgbox, condition true
Else 
{    
     Msgbox, condition false 
     Suspend, on
     Send A
     Suspend,  off
} 
Return 

B::
Condition := !Condition 
Return

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

Re: Is this even possible with AHK

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

~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

~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

tildechar = 

settimer, tildetest, 1000

tildetest:
tildechar = 1
sleep, 5000
tildechar = 2

return

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

return

ESC::ExitApp
Rohwedder
Posts: 7623
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

tildechar = 

settimer, tildetest, 10000 ;Period 10 seconds

tildetest:
tildechar = 1
ToolTip, % "tildechar: "tildechar "  Line: " A_LineNumber
sleep, 5000 ;Sleep 5 seconds
tildechar = 2
ToolTip, % "tildechar: "tildechar "  Line: " A_LineNumber
return

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

return

ESC::ExitApp
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

tildechar = 

settimer, tildetest, 10000 ;Period 10 seconds

tildetest:
tildechar = 1
ToolTip, % "tildechar: "tildechar "  Line: " A_LineNumber
sleep, 5000 ;Sleep 5 seconds
tildechar = 2
ToolTip, % "tildechar: "tildechar "  Line: " A_LineNumber
return

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

return

ESC::ExitApp
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 (v1)”

Who is online

Users browsing this forum: Descolada and 223 guests