Code: Select all
#Requires AutoHotkey v1.1
#SingleInstance Force
F2::
BlockKeybdInput.On()
Sleep 2000
BlockKeybdInput.Off()
return
Class BlockKeybdInput ; v1.1
{ ; No administrator rights required
On(obj:="ih") {
if !this[obj].InProgress {
this[obj]:=InputHook()
this[obj].MinSendLevel:=101
this[obj].VisibleNonText:=false
this[obj].Start()
}
}
Off(obj:="ih") {
if this[obj].InProgress
this[obj].Stop()
}
}
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
BlockKeybdInput:=BlockKeybdInputObj()
F2::
{
BlockKeybdInput.On()
Sleep 2000
BlockKeybdInput.Off()
}
Class BlockKeybdInputObj ; v2.0
{ ; No administrator rights required
On(obj:="ih") {
Try this.%obj% ; <-- Error: This value of type "BlockKeybdInput" has no property named "ih".
Catch {
this.%obj%:=InputHook()
}
if !this.%obj%.InProgress {
this.%obj%.MinSendLevel:=101
this.%obj%.VisibleNonText:=false
this.%obj%.Start()
}
}
Off(obj:="ih") {
Try this.%obj%
Catch {
this.%obj%:=InputHook()
}
if this.%obj%.InProgress
this.%obj%.Stop()
}
}
Here is my v1 code.
And I tried to convert this v1 code to v2.
I used Try Catch to verify that obj exists, but I don't think this is the right answer.
I am not familiar with v2. Am I right? Please someone fix my ugly code...
Code: Select all
#Requires AutoHotkey v1.1
#SingleInstance Force
F3::
New_SomeClass:=New SomeClass
New_SomeClass.Method_1()
New_SomeClass.Method_2()
SomeClass.Method_1()
SomeClass.Method_2()
ExitApp
Class SomeClass
{
Method_1() {
var1:="str1"
this[var1]:="STR1"
this.str2:="STR2"
}
Method_2() {
var1:="str1"
Msgbox % this[var1]
Msgbox % this.str2
}
}
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
F3::
{
New_SomeClass:=SomeClass()
New_SomeClass.Method_1()
New_SomeClass.Method_2()
SomeClass().Method_1()
SomeClass().Method_2() ; <-- Error: This value of type "SomeClass" has no property named "str1".
; Error: This value of type "SomeClass" has no property named "str2".
ExitApp
}
Class SomeClass
{
Method_1() {
var1:="str1"
Try this.%var1%
Catch
this.%var1%:="STR1"
this.str2:="STR2"
}
Method_2() {
var1:="str1"
Msgbox this.%var1%
Msgbox this.str2
}
}
Also, I wonder if "this." can no longer be used to share its property
without constructing a new instance of that class.
I'm sorry but I don't speak English well,
so if I missed the relevant explanation in quick reference, please someone let me know that link.
Thank you for reading it:)