ahk documentation questions

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
marypoppins_1
Posts: 142
Joined: 28 Oct 2020, 02:58

ahk documentation questions

Post by marypoppins_1 » 10 May 2024, 07:21

hello. this topic will include some questions I have regarding ahk documentation. thanks in advance for all help.
You can define a custom combination of two (and only two) keys (except controller buttons) by using & between them. In the example below, you would hold down Numpad0 then press Numpad1 or Numpad2 to trigger one of the hotkeys
1. can each of these have modifier keys too? ex: shift + numpad2 + ctrl + numpad8 (order doesn't matter)

User avatar
mikeyww
Posts: 28871
Joined: 09 Sep 2014, 18:38

Re: ahk documentation questions

Post by mikeyww » 10 May 2024, 08:24

Hello,

These questions are OK but you can answer them more quickly and directly by running your test scripts. In other words, to answer the question, "Will my script work?", you can always run your script to find out! Your script might even execute more quickly than this forum server could record your post! :)

The same page that you are citing also discusses combinations of three or more keys, and provides you with an example of how to approach that. When you have a script that does not work, you can post it here to get specific feedback about it.

If you have more questions, I would avoid hiding them here. Post a list, or create new threads if you feel that the topics differ much.

marypoppins_1
Posts: 142
Joined: 28 Oct 2020, 02:58

Re: ahk documentation questions

Post by marypoppins_1 » 24 May 2024, 22:19

okaythank you mikey. another question: in the docs they didnt define / show how you would use this

Code: Select all

{ ... } / Object	Creates an Object from a list of property name and value pairs.
is it a way to create an object without having a class and without being able to easily make more objects with similar properties / methods??
not sure if this example is right but

Code: Select all

obj1 = {
name = "mary"
int2 = 16
myfunc(x=16){
return sqrt(x)
}
}
thanks in advance

User avatar
mikeyww
Posts: 28871
Joined: 09 Sep 2014, 18:38

Re: ahk documentation questions

Post by mikeyww » 25 May 2024, 06:29

You can use a :arrow: map object.

Code: Select all

#Requires AutoHotkey v2.0
obj1 := Map(
   'name', 'mary'
 , 'int2', 16
)
MsgBox myfunc(obj1['int2']), 'Result', 'Iconi'

myfunc(n) {
 Return Sqrt(n)
}

marypoppins_1
Posts: 142
Joined: 28 Oct 2020, 02:58

Re: ahk documentation questions

Post by marypoppins_1 » 25 May 2024, 07:43

okay thank you. this works but I'm not sure if I wasn't clear. creating an object using map is like creating a dictionary, no? what I meant was that: is it possible to create an object as an instance of a class without creating a class? so I would just use this (or something similar if it exists) and use the syntax associated with objects as instances of a class. (ex x.name, x.myfunction() , ...)

Code: Select all

x = {
name= "alice"
age = 22
}

User avatar
thqby
Posts: 560
Joined: 16 Apr 2021, 11:18
Contact:

Re: ahk documentation questions

Post by thqby » 25 May 2024, 07:52

v2.1

Code: Select all

obj1 := {
name : "mary",
int2 : 16,
myfunc: (this,x:=16){
return sqrt(x)
}
}
Last edited by thqby on 25 May 2024, 08:12, edited 1 time in total.

marypoppins_1
Posts: 142
Joined: 28 Oct 2020, 02:58

Re: ahk documentation questions

Post by marypoppins_1 » 25 May 2024, 08:03

@thqby I tried your way and I get
Error: Unexpected "{"

038: Return
040: {
▶ 041: obj1 := { name : "mary" int2 : 16 myfunc: (this,int2:=16){ return sqrt(int2) } }
048: msgbox(type(obj1))
049: }
I also tried my way I get something weird:
Error: Missing "propertyname:" in object literal.

038: Return
040: {
▶ 041: x := { name = "alice" age = 22 }

User avatar
thqby
Posts: 560
Joined: 16 Apr 2021, 11:18
Contact:

Re: ahk documentation questions

Post by thqby » 25 May 2024, 08:10

V2.1 is required, not V2.0.

In addition, some line breaks are necessary.

marypoppins_1
Posts: 142
Joined: 28 Oct 2020, 02:58

Re: ahk documentation questions

Post by marypoppins_1 » 25 May 2024, 08:39

okay so I guess i'll either use classes or maps like how mikey suggested. thank you

Post Reply

Return to “Ask for Help (v2)”