The new
keyword is not working in AutoHotkey v2:
#Requires AutoHotkey v2.0
MsgBox "AHK Version: " A_AhkVersion
ih := new InputHook("L1 T0.5")
ih.Start()
key := ih.Wait() ; Wait for one key press (or timeout)
ih.Stop()
MsgBox "Key pressed: " key
If I comment that out I get:
#Requires AutoHotkey v2.0
MsgBox "AHK Version: " A_AhkVersion
;ih := new InputHook("L1 T0.5")
;ih.Start()
;key := ih.Wait() ; Wait for one key press (or timeout)
;ih.Stop()
;MsgBox "Key pressed: " key
How do I fix this?
The
new
operator has been removed. Instead, just omit the operator, as in MyClass(). To construct an object based on another object that is not a class, create it with {} or Object() (or by any other means) and set its base. __Init and __New can be called explicitly if needed, but generally this is only appropriate when instantiating a class.
MsgBox "AHK Version: " A_AhkVersion
ih := InputHook("L1 T0.5")
ih.Start()
key := ih.Wait() ; Wait for one key press (or timeout)
ih.Stop()
MsgBox "Key pressed: " key