Page 1 of 1

ahk documentation questions

Posted: 10 May 2024, 07:21
by marypoppins_1
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)

Re: ahk documentation questions

Posted: 10 May 2024, 08:24
by mikeyww
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.

Re: ahk documentation questions

Posted: 24 May 2024, 22:19
by marypoppins_1
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

Re: ahk documentation questions

Posted: 25 May 2024, 06:29
by mikeyww
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)
}

Re: ahk documentation questions

Posted: 25 May 2024, 07:43
by marypoppins_1
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
}

Re: ahk documentation questions

Posted: 25 May 2024, 07:52
by thqby
v2.1

Code: Select all

obj1 := {
name : "mary",
int2 : 16,
myfunc: (this,x:=16){
return sqrt(x)
}
}

Re: ahk documentation questions

Posted: 25 May 2024, 08:03
by marypoppins_1
@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 }

Re: ahk documentation questions

Posted: 25 May 2024, 08:10
by thqby
V2.1 is required, not V2.0.

In addition, some line breaks are necessary.

Re: ahk documentation questions

Posted: 25 May 2024, 08:39
by marypoppins_1
okay so I guess i'll either use classes or maps like how mikey suggested. thank you