Issue with gui hotkey control Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Hellbent
Posts: 737
Joined: 23 Sep 2017, 13:34

Issue with gui hotkey control

17 Oct 2019, 09:20

I don't think that it's strictly a issue with the hotkey control, but that's where I have encountered it so...


Here's the issue.

If you set the hotkey control to a number (1-0) and then update it, the value gets updated with no problems.
If you then change it to Shift + the same number and update it won't see it as a different value (likewise with the reverse).
But... if you were to do the exact same thing with a letter (a-z) everything works fine.

Is this a bug or something else?


Here is a simple script that can be used to demonstrate what I'm talking about.

Try this.
;----------------------

set the hotkey to 1 and update.
next set the hotkey to Shit + 1 and update again.

Code: Select all


#SingleInstance,Force
Gui,1:+AlwaysOnTop

Gui,1:Add,Hotkey,w200 vMyHotkey,
Gui,1:Add,Button,gUpdateHK,Update Hotkey
Gui,1:Show,,Demo of problem
return
GuiClose:
*ESC::
	ExitApp
	
UpdateHK:
	Gui,1:+OwnDialogs
	GuicontrolGet,NewKey,1:,MyHotkey
	;----------------------------------
	;Testing
	msgbox,% Newkey "`n" MyHotkey
	if(Newkey!=MyHotkey){  ; this test is the same as the last else if 
		msgbox,not the same
	}
	;---------------------------------------
	;Normal logic (only needed to update the value of "MyHotkey")
	if(Newkey=""&&MyHotkey!=""){
		ToolTip, in 1
		MyHotkey:=Newkey
	}else if(Newkey!=MyHotkey&&MyHotkey!=""){
		ToolTip, in 2
		MyHotkey:=Newkey
	}else if(Newkey!=MyHotkey){
		ToolTip, in 3
		MyHotkey:=Newkey
	}
	SetTimer,TOTT,-1000	
	return
	
TOTT:
	ToolTip,
	return
User avatar
jNizM
Posts: 2508
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Issue with gui hotkey control

17 Oct 2019, 09:32

Looks more like ahk interprets the variable +N as N

Code: Select all

var1 := 1
var2 := +1

if (var1 = var2)
	MsgBox % "same`n" var1 " = " var2
if (var1 != var2)
	MsgBox % "different`n" var1 " = " var2
While pure strings works.

Code: Select all

var1 := "a"
var2 := "+a"

if (var1 = var2)
	MsgBox % "same`n" var1 " = " var2
if (var1 != var2)
	MsgBox % "different`n" var1 " = " var2
I think it's because he just sees it as a positive number.
1 is the same like +1 in math
1 is not the same like -1 in math
[AHK] 1.1.30.03 x64 Unicode | [WIN] 10 Pro (Version 1903) x64 | [GitHub] Profile
Donations are appreciated if I could help you
Hellbent
Posts: 737
Joined: 23 Sep 2017, 13:34

Re: Issue with gui hotkey control

17 Oct 2019, 09:50

jNizM wrote:
17 Oct 2019, 09:32

Code: Select all

var1 := 1
var2 := +1

if (var1 = var2)
	MsgBox % "same`n" var1 " = " var2
if (var1 != var2)
	MsgBox % "different`n" var1 " = " var2
While pure strings works.
I think it's because he just sees it as a positive number.
1 is the same like +1 in math
1 is not the same like -1 in math
Still has the same issue when assigned as a string

Code: Select all

var1 := "1"
var2 := "+1"

if (var1 = var2)
	MsgBox % "same`n" var1 " = " var2
if (var1 != var2)
	MsgBox % "different`n" var1 " = " var2
Hellbent
Posts: 737
Joined: 23 Sep 2017, 13:34

Re: Issue with gui hotkey control  Topic is solved

17 Oct 2019, 20:22

I've made a bug report about this so i'll just use a work around in my script.

Either.

Code: Select all

else if((Newkey!=MyHotkey&&MyHotkey!="")||(Newkey=MyHotkey&&Newkey!=""))
or

Code: Select all

else if((Newkey!=MyHotkey&&MyHotkey!="")||(Newkey=MyHotkey&&Strlen(Newkey)!=Strlen(MyHotkey)))
That last one makes me laugh a bit :roll:

Anyway, don't think that there's much else I can do, so topic solved???
Hellbent
Posts: 737
Joined: 23 Sep 2017, 13:34

Re: Issue with gui hotkey control

17 Oct 2019, 21:34

Thanks to @gregster I have a better solution.

Code: Select all

else if((Newkey "" != MyHotkey "" &&MyHotkey!="")

Return to “Ask For Help”

Who is online

Users browsing this forum: asad41163, flyingDman, Gully and 43 guests