Page 1 of 1

Trouble with a funtion when named "Scale" or "vk1234"

Posted: 15 Aug 2017, 13:48
by wolf_II
Hi all,

I have trouble when I want to name a function "Scale".
Here is an example with a function named "xScale" and it works as intended.
When I rename the function to "Scale" as I desire (yes, I renamed all 3 occurrences of its name), the function does not work any more.

Code: Select all

#NoEnv
#SingleInstance, Force
SetBatchLines, -1

    Gui, Clock: New, HWNDhClock -Caption, Clock
    Gui, +0x00400000 ; WS_DLGFRAME (3D border)
    Gui, Margin, 5, 5
    Gui, Add, Text, w300 h300 Border
    Gui, Show

Return ; end of auto-execute section


ClockGuiClose:
ClockGuiEscape:
ExitApp


;-------------------------------------------------------------------------------
#If WinActive("ahk_id " hClock) ; hotkeys for GUI
;-------------------------------------------------------------------------------
    ^WheelUp::   xScale("Up")
    ^WheelDown:: xScale("Down")

#If ; off


;-------------------------------------------------------------------------------
xScale(d) { ; trouble with this funtion when named "Scale" or "vk1234"
;-------------------------------------------------------------------------------
    ToolTip, %d%, 50, 50
}



;-------------------------------------------------------------------------------
WM_LBUTTONDOWN() { ; move window
;-------------------------------------------------------------------------------
    static init := OnMessage(0x0201, "WM_LBUTTONDOWN")
    PostMessage, 0xA1, 2 ; WM_NCLBUTTONDOWN
}
Can anybody confirm, please? Better yet, can anybody explain please why this is?

I also have trouble with "vk1234" as a function name, which lets me think there might be some interference with scan code and/or virtual key code.
To clarify: I have no desire to name a function "vk1234", but I did test my "scan code" theory.

https://autohotkey.com/docs/Variables.htm explains about variable names.
I can't find a help topic about function names. I have assumed up til now that both are treated as "idioms" (if that is the correct term?), whose rules are explained in the docs.
I am obviously wrong about that too. :(

Thanks for reading! :)

Edit: I will likely change the function name to "Zoom()", but I still want to learn about this problem.

Re: Trouble with a funtion when named "Scale" or "vk1234"  Topic is solved

Posted: 15 Aug 2017, 16:38
by Helgef
This works fine,

Code: Select all

scan()
scan(){
	msgbox
}
your problem is that the one line hotkey is being interpreted as a remapping hotkey, ^WheelUp::sca, that is, ^WheelUp remapped to 9.
Try this in notepad, you see

Code: Select all

a::scan()
b::scaHELLOWORLD()
Keyhistory,

Code: Select all

SetKeyDelay,-1
001: Send,{Blind}{scan() DownTemp}
001: Return (0.16)
001: SetKeyDelay,-1
001: Send,{Blind}{scan() Up}
001: Return (1.76)
002: SetKeyDelay,-1
002: Send,{Blind}{scaHELLOWORLD() DownTemp}
002: Return (0.14)
002: SetKeyDelay,-1
002: Send,{Blind}{scaHELLOWORLD() Up}

Hotkeys wrote:However, if a hotkey needs to execute only a single line, that line can be listed to the right of the double-colon. In other words, the return is implicit:
So it is a bug.
Workaround,

Code: Select all

a::
	Scan()
return
or

Code: Select all

hotkey,a,scan
Cheers.

Edit: Tested on AHK 1.1.26.00 and latest (I think) v2

Re: Trouble with a funtion when named "Scale" or "vk1234"

Posted: 15 Aug 2017, 17:28
by wolf_II
Thanks Helgef. :thumbup:

I did notice before in the key history the 9 and did not understand where it came from.
So, Scale() is interpreted as only sca, where a is a hexadecimal 10, and apparently scan code 10 is the 9-key in the top row of the keyboard. The remaining le() is disregarded. Somewhat unintuitive.

I noticed in your example for me to test in Notepad that the script executes without even a function scaHELLOWORLD() being defined in the script. Excellent example!!
Thank you for taking the time and looking into this.

I probably should have mentioned that I tested on Win10 64-bit. The most recent update came a couple of days ago, it is called "Creators Update" I think, but that is irrelevant to the problem.
What is relevant: I tested with AHK v1.1.26.01 64-bit.

I will wait about two days from now to see if there will be more responses, then I will mark your post as "accepted answer" and post in the subforum "Bug Reports".
Unless you want to post a bug report yourself, which is OK by me. After all, you have done all the work.

I highly appreciate your input. :D

Re: Trouble with a funtion when named "Scale" or "vk1234"

Posted: 15 Aug 2017, 17:50
by Helgef
So Scale() [...]
Indeed, that is how it seems.
Waiting is good, maybe someone knows where it is documented or if it has already been reported. You can post.

Re: Trouble with a funtion when named "Scale" or "vk1234"

Posted: 17 Aug 2017, 12:27
by wolf_II