update keycode type use uint16 with gohook, not type convert

This commit is contained in:
vcaesar 2020-03-17 12:33:31 -04:00
parent bec66ba51f
commit f765226230
2 changed files with 8 additions and 6 deletions

View File

@ -47,7 +47,7 @@ func AddEvent(key string) bool {
} }
if len(key) > 1 && !mouseBool { if len(key) > 1 && !mouseBool {
key = strconv.Itoa(Keycode[key].(int)) key = strconv.Itoa(int(Keycode[key]))
} }
geve := hook.AddEvent(key) geve := hook.AddEvent(key)
@ -93,7 +93,7 @@ func AddEvents(key string, arr ...string) bool {
l := len(arr) l := len(arr)
if l > 0 { if l > 0 {
for i := 0; i < l; i++ { for i := 0; i < l; i++ {
ukey := uint16(Keycode[arr[i]].(int)) ukey := Keycode[arr[i]]
if e.Kind == hook.KeyHold && e.Keycode == ukey { if e.Kind == hook.KeyHold && e.Keycode == ukey {
k++ k++
@ -115,7 +115,7 @@ func AddEvents(key string, arr ...string) bool {
ct = true ct = true
} }
if ct && e.Kind == hook.KeyUp && e.Keycode == uint16(Keycode[key].(int)) { if ct && e.Kind == hook.KeyUp && e.Keycode == Keycode[key] {
hook.End() hook.End()
// k = 0 // k = 0
break break
@ -148,7 +148,7 @@ func AddMouse(btn string, x ...int16) bool {
ct = true ct = true
} }
if ct && e.Kind == hook.MouseDown && int(e.Button) == ukey { if ct && e.Kind == hook.MouseDown && e.Button == ukey {
hook.End() hook.End()
break break
} }

View File

@ -10,8 +10,10 @@
package robotgo package robotgo
type uMap map[string]uint16
// MouseMap robotgo hook mouse's code map // MouseMap robotgo hook mouse's code map
var MouseMap = Map{ var MouseMap = uMap{
"left": 1, "left": 1,
"right": 2, "right": 2,
"center": 3, "center": 3,
@ -22,7 +24,7 @@ var MouseMap = Map{
} }
// Keycode robotgo hook key's code map // Keycode robotgo hook key's code map
var Keycode = Map{ var Keycode = uMap{
"`": 41, "`": 41,
"1": 2, "1": 2,
"2": 3, "2": 3,