How to use hotkey object functions Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
cgx5871
Posts: 319
Joined: 26 Jul 2018, 14:02

How to use hotkey object functions

19 May 2024, 03:17

Code: Select all

;~   ^1  ----  +1!1
;~   ^2  ----  +2!2
;~   ^a  ----  +a!a
Loop 10
	Hotkey "^" A_Index, a.b(A_Index)	;~ Error: Nonexistent hotkey.

class a {
	static b(s){
		Send "+" s "!" s
	}
}
User avatar
Noitalommi_2
Posts: 295
Joined: 16 Aug 2023, 10:58

Re: How to use hotkey object functions

19 May 2024, 04:06

Hi.

Edit2: Couldn't get it to work with a loop but this does at least use the parameter.

Code: Select all

Hotkey "<^" 1, (*) => a.b("Test 1")
Hotkey "<^" 2, (*) => a.b("Test 2")


class a {
	static b(s){
		SendText "+" s "!" s
	}
}
User avatar
Noitalommi_2
Posts: 295
Joined: 16 Aug 2023, 10:58

Re: How to use hotkey object functions

19 May 2024, 06:27

Another try.

Code: Select all

Loop 10
	Hotkey "<^" A_Index-1, f.Bind(A_Index-1) ; Left Ctrl + 0 - 9, binds A_Index-1
f(Parameter, ThisHotkey) => a.b(Parameter, ThisHotkey) ; You can certainly write this in the line above but I don't know how.


class a {
	static b(para1, para2){
		SendText "+" para1 "!" para1 ", Hotkey= " para2
	}
}
User avatar
Noitalommi_2
Posts: 295
Joined: 16 Aug 2023, 10:58

Re: How to use hotkey object functions

19 May 2024, 06:55

@niCode
Had this as my first attempt as well, check the return Value, it's not correct.

Edit: Post is gone or I'm hallucinating. :lol:
niCode
Posts: 316
Joined: 17 Oct 2022, 22:09

Re: How to use hotkey object functions

19 May 2024, 06:59

Noitalommi_2 wrote:
19 May 2024, 06:55
@niCode
Had this as my first attempt as well, check the return Value, it's not correct.

Edit: Post is gone or I'm hallucinating. :lol:
I realized my mistake after. Didn't catch the control modifier symbol because it's six in the morning and haven't slept lol.

This seems like it works though.

Code: Select all

loop 10 {
    num := SubStr(A_Index, -1)
    Hotkey('^' num, ObjBindMethod(a, 'b', num))
}

class a {
    static b(s, key) {
        SendText('+' s '!' s)
    }
}
just me
Posts: 9550
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to use hotkey object functions  Topic is solved

19 May 2024, 07:30

A bit more straight:

Code: Select all

#Requires AutoHotkey v2.0
For Key In StrSplit("0123456789")
    Hotkey('^' Key, (HK) => A.B(SubStr(HK, -1)))

Class A {
    Static B(K) {
        ToolTip('+' K '!' K)
    }
}

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Draken, vmech and 46 guests