Skip to content

Commit 0b2d254

Browse files
authored
Merge pull request #1 from Chaoses-Ib/develop
Develop
2 parents 6f49a0a + 5a07fb2 commit 0b2d254

36 files changed

+2235
-973
lines changed

AhkDll.Ahk/v1/IbAhkSend.ahk

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,42 @@
11
; IbAhkSendLib (v1)
22
; Description: Enable AHK to send keystrokes by drivers.
33
; Author: Chaoses Ib
4-
; Version: 210815
4+
; Version: 0.2
55
; Git: https://github.com/Chaoses-Ib/IbAhkSendLib
66

7-
IbSendInit(mode := 0){
8-
static hModule := DllCall("LoadLibrary", "Str", A_ScriptDir "\IbAhkSend.dll", "Ptr")
7+
IbSendInit(send_type := "AnyDriver", mode := 1, args*){
8+
workding_dir := A_WorkingDir
9+
SetWorkingDir, %A_ScriptDir%
10+
11+
static hModule := DllCall("LoadLibrary", "Str", "IbAhkSend.dll", "Ptr")
912
if (hModule == 0){
1013
if (A_PtrSize == 4)
11-
throw "LibLoadingFailed: Please use AutoHotkey x64"
12-
else if (!FileExist(A_ScriptDir "\IbAhkSend.dll"))
13-
throw "LibLoadingFailed: Please put IbAhkSend.dll with your script file (or use AHK v2 instead, which can locate those DLLs that are put with the library files)"
14+
throw "SendLibLoadFailed: Please use AutoHotkey x64"
15+
else if (!FileExist("IbAhkSend.dll"))
16+
throw "SendLibLoadFailed: Please put IbAhkSend.dll with your script file (or use AHK v2 instead, which can locate those DLLs that are put with the library files)"
1417
else
15-
throw "LibLoadingFailed"
18+
throw "SendLibLoadFailed"
1619
}
1720

18-
result := DllCall("IbAhkSend\IbAhkSendInit", "Int")
21+
if (send_type == "AnyDriver")
22+
result := DllCall("IbAhkSend\IbAhkSendInit", "Int", 0, "Int", 0, "Ptr", 0, "Int")
23+
else if (send_type == "SendInput")
24+
result := DllCall("IbAhkSend\IbAhkSendInit", "Int", 1, "Int", 0, "Ptr", 0, "Int")
25+
else if (send_type == "Logitech")
26+
result := DllCall("IbAhkSend\IbAhkSendInit", "Int", 2, "Int", 0, "Ptr", 0, "Int")
27+
else if (send_type == "DD"){
28+
if (args.MaxIndex() == 1)
29+
result := DllCall("IbAhkSend\IbAhkSendInit", "Int", 3, "Int", 0, "WStr", args[1], "Int")
30+
else
31+
result := DllCall("IbAhkSend\IbAhkSendInit", "Int", 3, "Int", 0, "Ptr", 0, "Int")
32+
} else
33+
throw "Invalid send type"
34+
35+
SetWorkingDir, %workding_dir%
36+
1937
if (result != 0){
20-
error_text := ["DeviceNotFound", "DeviceOpeningFailed", "LogiSettingsNotFound"]
21-
throw error_text[result - 1]
38+
error_text := ["InvalidArgument", "LibraryNotFound", "LibraryLoadFailed", "LibraryError", "DeviceCreateFailed", "DeviceNotFound", "DeviceOpenFailed"]
39+
throw error_text[result]
2240
}
2341

2442
if (mode != 0){
@@ -29,14 +47,14 @@ IbSendInit(mode := 0){
2947
IbSendMode(mode){
3048
static ahk_mode := ""
3149
if (mode == 1){
32-
DllCall("IbAhkSend\IbAhkSendInputHookBegin")
50+
DllCall("IbAhkSend\IbAhkSendInputHook", "Int", 1)
3351
ahk_mode := A_SendMode
3452
SendMode Input
3553
} else if (mode == 0){
3654
SendMode %ahk_mode%
37-
DllCall("IbAhkSend\IbAhkSendInputHookEnd")
55+
DllCall("IbAhkSend\IbAhkSendInputHook", "Int", 0)
3856
} else {
39-
throw "Invalid argument"
57+
throw "Invalid send mode"
4058
}
4159
}
4260

@@ -45,9 +63,12 @@ IbSendDestroy(){
4563
;DllCall("FreeLibrary", "Ptr", hModule)
4664
}
4765

66+
IbSyncKeyStates(){
67+
DllCall("IbAhkSend\IbAhkSendSyncKeyStates")
68+
}
4869

4970
IbSend(keys){
50-
DllCall("IbAhkSend\IbAhkSendInputHookBegin") ;or IbSendMode(1)
71+
DllCall("IbAhkSend\IbAhkSendInputHook", "Int", 1) ;or IbSendMode(1)
5172
SendInput %keys%
52-
DllCall("IbAhkSend\IbAhkSendInputHookEnd") ;or IbSendMode(0)
73+
DllCall("IbAhkSend\IbAhkSendInputHook", "Int", 0) ;or IbSendMode(0)
5374
}

AhkDll.Ahk/v1/test/mode 0.ahk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#Include ..\IbAhkSend.ahk
55

6-
IbSendInit()
6+
IbSendInit("AnyDriver", 0)
77

88
IbSend("#r")
99
WinWaitActive, ahk_class #32770

AhkDll.Ahk/v1/test/mode 1.ahk

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
#Include ..\IbAhkSend.ahk
55

6-
IbSendInit(1)
7-
; or:
8-
;IbSendInit()
9-
;IbSendMode(1)
6+
IbSendInit()
107

118
Send #r
129
WinWaitActive, ahk_class #32770

AhkDll.Ahk/v1/test/mode ahk.ahk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ Send notepad`n
66

77
WinWaitActive, ahk_exe notepad.exe
88
Send Hello world+1
9-
MouseClickDrag, Left, 0, 0, 150, 50
9+
Sleep 100
10+
CoordMode, Mouse, Client
11+
MouseClickDrag, Left, 5, 5, 150, 50

AhkDll.Ahk/v1/test/type DD.ahk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#Include ..\IbAhkSend.ahk
2+
IbSendInit("DD") ;or IbSendInit("DD", 1, "C:\SomeDir\DD64.dll")
3+
#include mode ahk.ahk
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#Include ..\IbAhkSend.ahk
2+
IbSendInit("Logitech")
3+
#include mode ahk.ahk
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#Include ..\IbAhkSend.ahk
2+
IbSendInit("SendInput")
3+
#include mode ahk.ahk

AhkDll.Ahk/v2/IbAhkSend.ahk

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,68 @@
11
; IbAhkSendLib
22
; Description: Enable AHK to send keystrokes by drivers.
33
; Author: Chaoses Ib
4-
; Version: 210815
4+
; Version: 0.2
55
; Git: https://github.com/Chaoses-Ib/IbAhkSendLib
66

77
#DllLoad "*i IbAhkSend.dll" ;DllCall("LoadLibrary") cannot locate DLL correctly
88

9-
IbSendInit(mode := 0){
9+
IbSendInit(send_type := "AnyDriver", mode := 1, args*){
10+
workding_dir := A_WorkingDir
11+
SetWorkingDir(A_ScriptDir)
12+
1013
static hModule := DllCall("GetModuleHandle", "Str", "IbAhkSend.dll", "Ptr")
1114
if (hModule == 0){
1215
if (A_PtrSize == 4)
13-
throw "LibLoadingFailed: Please use AutoHotkey x64"
16+
throw "SendLibLoadFailed: Please use AutoHotkey x64"
1417
else
15-
throw "LibLoadingFailed"
18+
throw "SendLibLoadFailed"
1619
}
1720

18-
result := DllCall("IbAhkSend\IbAhkSendInit", "Int")
19-
if (result != 0){
21+
if (send_type == "AnyDriver")
22+
result := DllCall("IbAhkSend\IbAhkSendInit", "Int", 0, "Int", 0, "Ptr", 0, "Int")
23+
else if (send_type == "SendInput")
24+
result := DllCall("IbAhkSend\IbAhkSendInit", "Int", 1, "Int", 0, "Ptr", 0, "Int")
25+
else if (send_type == "Logitech")
26+
result := DllCall("IbAhkSend\IbAhkSendInit", "Int", 2, "Int", 0, "Ptr", 0, "Int")
27+
else if (send_type == "DD"){
28+
if (args.Length == 1)
29+
result := DllCall("IbAhkSend\IbAhkSendInit", "Int", 3, "Int", 0, "WStr", args[1], "Int")
30+
else
31+
result := DllCall("IbAhkSend\IbAhkSendInit", "Int", 3, "Int", 0, "Ptr", 0, "Int")
32+
} else
33+
throw "Invalid send type"
34+
35+
SetWorkingDir(workding_dir)
36+
37+
if (result !== 0){
2038
error_text := [
39+
"InvalidArgument",
40+
"LibraryNotFound",
41+
"LibraryLoadFailed",
42+
"LibraryError",
43+
"DeviceCreateFailed",
2144
"DeviceNotFound",
22-
"DeviceOpeningFailed",
23-
"LogiSettingsNotFound"
45+
"DeviceOpenFailed"
2446
]
25-
throw error_text[result - 1]
47+
throw error_text[result]
2648
}
2749

28-
if (mode != 0){
50+
if (mode !== 0){
2951
IbSendMode(mode)
3052
}
3153
}
3254

3355
IbSendMode(mode){
3456
static ahk_mode := ""
3557
if (mode == 1){
36-
DllCall("IbAhkSend\IbAhkSendInputHookBegin")
58+
DllCall("IbAhkSend\IbAhkSendInputHook", "Int", 1)
3759
ahk_mode := A_SendMode
3860
SendMode("Input")
3961
} else if (mode == 0){
4062
SendMode(ahk_mode)
41-
DllCall("IbAhkSend\IbAhkSendInputHookEnd")
63+
DllCall("IbAhkSend\IbAhkSendInputHook", "Int", 0)
4264
} else {
43-
throw "Invalid argument"
65+
throw "Invalid send mode"
4466
}
4567
}
4668

@@ -49,11 +71,14 @@ IbSendDestroy(){
4971
;DllCall("FreeLibrary", "Ptr", hModule)
5072
}
5173

74+
IbSyncKeyStates(){
75+
DllCall("IbAhkSend\IbAhkSendSyncKeyStates")
76+
}
5277

5378
IbSend(keys){
54-
DllCall("IbAhkSend\IbAhkSendInputHookBegin") ;or IbSendMode(1)
79+
DllCall("IbAhkSend\IbAhkSendInputHook", "Int", 1) ;or IbSendMode(1)
5580
SendInput(keys)
56-
DllCall("IbAhkSend\IbAhkSendInputHookEnd") ;or IbSendMode(0)
81+
DllCall("IbAhkSend\IbAhkSendInputHook", "Int", 0) ;or IbSendMode(0)
5782
}
5883

5984
IbClick(args*){

AhkDll.Ahk/v2/test/mode 0.ahk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
#Include "..\IbAhkSend.ahk"
55

6-
IbSendInit()
6+
IbSendInit("AnyDriver", 0)
77

88
IbSend("#r")
99
WinWaitActive("ahk_class #32770")
1010
IbSend("notepad`n")
1111

1212
WinWaitActive("ahk_exe notepad.exe")
1313
IbSend("Hello world+1")
14-
Sleep 100
14+
Sleep(100)
1515
IbMouseClickDrag("Left", 5, 5, 150, 50)

AhkDll.Ahk/v2/test/mode 1.ahk

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33

44
#Include "..\IbAhkSend.ahk"
55

6-
IbSendInit(1)
7-
; or:
8-
;IbSendInit()
9-
;IbSendMode(1)
6+
IbSendInit()
107

118
Send("#r")
129
WinWaitActive("ahk_class #32770")
1310
Send("notepad`n")
1411

1512
WinWaitActive("ahk_exe notepad.exe")
1613
Send("Hello world+1")
17-
Sleep 100
14+
Sleep(100)
1815
MouseClickDrag("Left", 5, 5, 150, 50)

0 commit comments

Comments
 (0)