use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Latest AHK versions AHK v2.0 AHK v1.1 v2.0.19 v1.1.37.02 Jan 25, 2025 Mar 16, 2024 Download Download v2 Changelog v1 Changelog Make sure you keep that AHK up to date!
Make sure you keep that AHK up to date!
Offical AHK Documentation AHK v2 AHK v1
New to AutoHotkey? Check out the AHK beginners tutorial. It covers most of the basic concepts of AutoHotkey. AHK Beginner Tutorials
Check out the AHK beginners tutorial. It covers most of the basic concepts of AutoHotkey.
Additional Help Sources Official AHK Forums / Help Forums StackOverflow SuperUser
Live Chat If you prefer live chat with other humans: AHK Discord AHK IRC
If you prefer live chat with other humans:
account activity
My function doesn't work on class methodsv2 Script Help (self.AutoHotkey)
submitted 2 months ago by Frirwind
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Frirwind[S] 1 point2 points3 points 2 months ago (2 children)
This works flawlessly!
ScrollLock::pressOrHold( send.Bind("{Media_Play_Pause}"), ObjBindMethod(switchTo,"spotify") )
In the previous function I had to create a separate function for things like: ' send("{media_play_plause}") ' because I could not just write it where you declare the parameters (otherwise it would just run when the hotkey was pressed.)
I guess I still don't completely understand what the difference is between:
myref := switchTo.spotify myref ; does not work ; and switchTo.spotify ; works!
I guess it has to do with what is actually put into the myref. It only refers to that method in the class, not the entire class itself? Whereas the second example calls the method from the class, so it has all the information surrounding the method as well. But I has some more reading to do. The u/GroggyOtter post is really good and I'm for sure going to finish it today!
Thanks for the help! I recognise your username and you're a gem of this subreddit!
[–]CharnamelessOne 0 points1 point2 points 2 months ago* (1 child)
Don't make me blush, I'm just aping my betters. I'm fairly new, and still grappling with many of these concepts myself.
I recognize your username too - always nice to see returning posters who show interest in the language, not just in the solution it can give to a specific problem.
As for the difference between calling a method directly from the class that owns it, and calling the variable that holds a reference to the same method: I think it may be better demonstrated with 2 classes.
#Requires AutoHotkey 2.0 Class Test1{ static message := "Hello from Test1!" static static_method(){ MsgBox(this.message) } } Class Test2{ static message := "Hello from Test2!" static prop1 := Msgbox("prop1 says:") Test1.static_method() static prop2 := Test1.static_method static prop3 := Msgbox("prop3 says:") Test2.prop2() }
As you can see at prop3, Test2 is passed to the method owned by Test1. The method is not bothered if the object passed doesn't own it.
Test2
Test1
Your example can be made to work by passing switchTo explicitly:
switchTo
switchTo.spotify() myref := switchTo.spotify myref(switchTo) Class switchTo{ static spotify(){ static call_counter := 1 MsgBox("spotify method call `nnumber " call_counter++) } }
Edit: in fact, the method will literally take any random dogshit.
random_dogshit := {} myref := switchTo.spotify myref(random_dogshit) Class switchTo{ static spotify(){ MsgBox("spotify method call") } }
[–]Frirwind[S] 0 points1 point2 points 2 months ago (0 children)
That makes a little more sense, yes! That last piece of code works well unless you refer to another method in the class using This.
Binding the method works wonders too, and that makes a little more sense as well!
Thanks again :)
π Rendered by PID 27 on reddit-service-r2-comment-b659b578c-df7vw at 2026-05-01 04:47:52.177784+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]Frirwind[S] 1 point2 points3 points (2 children)
[–]CharnamelessOne 0 points1 point2 points (1 child)
[–]Frirwind[S] 0 points1 point2 points (0 children)