File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1
1
package SuKey
2
2
3
3
import (
4
+ "fmt"
4
5
"github.com/go-vgo/robotgo"
5
6
"github.com/yuin/gopher-lua"
6
7
)
@@ -19,11 +20,42 @@ func Loader(L *lua.LState) int {
19
20
// 定义一个map类型的变量exports,其中key为string类型,value为lua.LGFunction类型
20
21
var exports = map [string ]lua.LGFunction {
21
22
"TypeStr" : typeStr , // 将myfunc函数注册到exports中
23
+ "KeyTap" : keyTap ,
24
+ }
25
+
26
+ // keyTap函数接收一个LState类型的参数L,返回一个int类型的值
27
+ func keyTap (L * lua.LState ) int {
28
+ // 从L中获取第一个参数,转换为table类型
29
+ tbl := L .ToTable (1 )
30
+ // 将table转换为字符串数组
31
+ var arr []string
32
+ tbl .ForEach (func (i lua.LValue , j lua.LValue ) {
33
+ arr = append (arr , j .String ())
34
+ })
22
35
36
+ // 打印字符串数组
37
+ fmt .Println (arr )
38
+ // 如果字符串数组长度大于1,则调用robotgo包中的KeyTap函数,传入第一个元素和剩余元素组成的切片
39
+ if len (arr ) > 1 {
40
+ robotgo .KeyTap (arr [0 ], arr [1 :])
41
+ } else {
42
+ // 否则,只传入第一个元素
43
+ robotgo .KeyTap (arr [0 ])
44
+ }
45
+ // 返回0
46
+ return 0
23
47
}
24
48
25
49
func typeStr (L * lua.LState ) int {
26
50
str := L .ToString (1 )
27
51
robotgo .TypeStr (str )
28
52
return 0
29
53
}
54
+
55
+ /*self := L.CheckTable(1)
56
+ value := lua.LNumber(0)
57
+ // 第二个为可选参数
58
+ if L.GetTop() >= 2 {
59
+ value = L.CheckNumber(2)
60
+ }
61
+ current := L.GetField(self, "value").(lua.LNumber)*/
Original file line number Diff line number Diff line change 1
1
print (" Hello World!" )
2
2
local m = require (" CallGo" )
3
3
local key = require (" SuKey" )
4
+ key .KeyTap ({" esc" , " ctrl" , " shift" })
4
5
key .TypeStr (" 0000000" )
5
6
m .myfunc ()
6
7
print (m .name )
You can’t perform that action at this time.
0 commit comments