Skip to content

Commit 0be7f6b

Browse files
committed
添加tap按键功能
1 parent 9385d5f commit 0be7f6b

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

GokeyLua/Tool/SuKey/SuKey.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package SuKey
22

33
import (
4+
"fmt"
45
"github.com/go-vgo/robotgo"
56
"github.com/yuin/gopher-lua"
67
)
@@ -19,11 +20,42 @@ func Loader(L *lua.LState) int {
1920
// 定义一个map类型的变量exports,其中key为string类型,value为lua.LGFunction类型
2021
var exports = map[string]lua.LGFunction{
2122
"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+
})
2235

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
2347
}
2448

2549
func typeStr(L *lua.LState) int {
2650
str := L.ToString(1)
2751
robotgo.TypeStr(str)
2852
return 0
2953
}
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)*/

bin/GokeyLua.exe

24.9 KB
Binary file not shown.

bin/main.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
print("Hello World!")
22
local m = require("CallGo")
33
local key = require("SuKey")
4+
key.KeyTap({"esc", "ctrl", "shift"})
45
key.TypeStr("0000000")
56
m.myfunc()
67
print(m.name)

0 commit comments

Comments
 (0)