mirror of
https://github.com/robotn/gohook.git
synced 2025-04-19 07:57:43 +08:00
Compare commits
No commits in common. "master" and "v0.31.1" have entirely different histories.
28
.github/issue_template.md
vendored
28
.github/issue_template.md
vendored
@ -1,28 +0,0 @@
|
|||||||
1. Please **speak English (English only)**, this is the language everybody of us can speak and write.
|
|
||||||
2. Please take a moment to **search** that an issue **doesn't already exist**.
|
|
||||||
3. Please make sure `Golang, GCC` is installed correctly before installing Gohook.
|
|
||||||
<!-- 4. Please ask questions or config/deploy problems on our Gitter channel: https://gitter.im/robotn/gohook -->
|
|
||||||
5. Please give all relevant information below for bug reports, incomplete details will be handled as an invalid report.
|
|
||||||
|
|
||||||
**You MUST delete the content above including this line before posting, otherwise your issue will be invalid.**
|
|
||||||
|
|
||||||
|
|
||||||
- Gohook version (or commit ref):
|
|
||||||
- Go version:
|
|
||||||
- Gcc version:
|
|
||||||
- Operating system and bit:
|
|
||||||
- Resolution:
|
|
||||||
- Can you reproduce the bug at [Examples](https://github.com/robotn/gohook/blob/master/examples/main.go):
|
|
||||||
- [ ] Yes (provide example code)
|
|
||||||
- [ ] No
|
|
||||||
- [ ] Not relevant
|
|
||||||
- Provide example code:
|
|
||||||
|
|
||||||
```Go
|
|
||||||
|
|
||||||
```
|
|
||||||
- Log gist:
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
...
|
|
25
.github/pull_request_template.md
vendored
25
.github/pull_request_template.md
vendored
@ -1,25 +0,0 @@
|
|||||||
The pull request will be closed without any reasons if it does not satisfy any of following requirements:
|
|
||||||
|
|
||||||
1. Make sure you are targeting the `master` branch, pull requests on release branches are only allowed for bug fixes.
|
|
||||||
2. Add new features, please provide the reasons and test code.
|
|
||||||
3. Please read contributing guidelines: [CONTRIBUTING](https://github.com/robotn/gohook/blob/master/CONTRIBUTING.md)
|
|
||||||
4. Describe what your pull request does and which issue you're targeting (if any and **Please use English**)
|
|
||||||
5. ... if it is not related to any particular issues, explain why we should not reject your pull request.
|
|
||||||
6. The Commits must **use English**, must be test and No useless submissions.
|
|
||||||
|
|
||||||
**You MUST delete the content above including this line before posting, otherwise your pull request will be invalid.**
|
|
||||||
|
|
||||||
|
|
||||||
**Please provide Issues links to:**
|
|
||||||
|
|
||||||
- Issues: #1
|
|
||||||
|
|
||||||
**Provide test code:**
|
|
||||||
|
|
||||||
```Go
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
...
|
|
8
.github/workflows/go.yml
vendored
8
.github/workflows/go.yml
vendored
@ -10,10 +10,10 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Go 1.23.0
|
- name: Set up Go 1.17
|
||||||
uses: actions/setup-go@v1
|
uses: actions/setup-go@v1
|
||||||
with:
|
with:
|
||||||
go-version: 1.23.0
|
go-version: 1.17
|
||||||
id: go
|
id: go
|
||||||
|
|
||||||
- name: Check out code into the Go module directory
|
- name: Check out code into the Go module directory
|
||||||
@ -22,6 +22,10 @@ jobs:
|
|||||||
- name: Get dependencies
|
- name: Get dependencies
|
||||||
run: |
|
run: |
|
||||||
go get -v -t -d ./...
|
go get -v -t -d ./...
|
||||||
|
# if [ -f Gopkg.toml ]; then
|
||||||
|
# curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
|
||||||
|
# dep ensure
|
||||||
|
# fi
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: go build -v .
|
run: go build -v .
|
||||||
|
24
README.md
24
README.md
@ -7,20 +7,6 @@
|
|||||||
[](https://godoc.org/github.com/robotn/gohook)
|
[](https://godoc.org/github.com/robotn/gohook)
|
||||||
<!-- This is a work in progress. -->
|
<!-- This is a work in progress. -->
|
||||||
|
|
||||||
## Requirements (Linux):
|
|
||||||
|
|
||||||
[Robotgo-requirements-event](https://github.com/go-vgo/robotgo#requirements)
|
|
||||||
|
|
||||||
## Install:
|
|
||||||
|
|
||||||
With Go module support (Go 1.11+), just import:
|
|
||||||
|
|
||||||
```go
|
|
||||||
import "github.com/robotn/gohook"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Examples:
|
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@ -45,11 +31,7 @@ func add() {
|
|||||||
|
|
||||||
fmt.Println("--- Please press w---")
|
fmt.Println("--- Please press w---")
|
||||||
hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) {
|
hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) {
|
||||||
fmt.Println("keyDown: ", "w")
|
fmt.Println("w")
|
||||||
})
|
|
||||||
|
|
||||||
hook.Register(hook.KeyUp, []string{"w"}, func(e hook.Event) {
|
|
||||||
fmt.Println("keyUp: ", "w")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
s := hook.Start()
|
s := hook.Start()
|
||||||
@ -57,10 +39,10 @@ func add() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func low() {
|
func low() {
|
||||||
evChan := hook.Start()
|
EvChan := hook.Start()
|
||||||
defer hook.End()
|
defer hook.End()
|
||||||
|
|
||||||
for ev := range evChan {
|
for ev := range EvChan {
|
||||||
fmt.Println("hook: ", ev)
|
fmt.Println("hook: ", ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ environment:
|
|||||||
PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH%
|
PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH%
|
||||||
# - COMPILER: MINGW_W64
|
# - COMPILER: MINGW_W64
|
||||||
# ARCHITECTURE: x64
|
# ARCHITECTURE: x64
|
||||||
GOVERSION: 1.23.0
|
GOVERSION: 1.17.1
|
||||||
# GOPATH: c:\gopath
|
# GOPATH: c:\gopath
|
||||||
|
|
||||||
# scripts that run after cloning repository
|
# scripts that run after cloning repository
|
||||||
|
150
event.go
150
event.go
@ -1,150 +0,0 @@
|
|||||||
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
package hook
|
|
||||||
|
|
||||||
import "strconv"
|
|
||||||
|
|
||||||
/*
|
|
||||||
___________ ____ _______ .__ __. .___________.
|
|
||||||
| ____\ \ / / | ____|| \ | | | |
|
|
||||||
| |__ \ \/ / | |__ | \| | `---| |----`
|
|
||||||
| __| \ / | __| | . ` | | |
|
|
||||||
| |____ \ / | |____ | |\ | | |
|
|
||||||
|_______| \__/ |_______||__| \__| |__|
|
|
||||||
*/
|
|
||||||
|
|
||||||
// AddEvent add event listener,
|
|
||||||
//
|
|
||||||
// parameters for the string type,
|
|
||||||
// the keyboard corresponding key parameters,
|
|
||||||
//
|
|
||||||
// mouse arguments: mleft, center, mright, wheelDown, wheelUp,
|
|
||||||
// wheelLeft, wheelRight.
|
|
||||||
//
|
|
||||||
// Use "hook.AddEvents()" or "gohook" add asynchronous event listener
|
|
||||||
func AddEvent(key string) bool {
|
|
||||||
var (
|
|
||||||
// cs *C.char
|
|
||||||
mArr = []string{"mleft", "center", "mright", "wheelDown",
|
|
||||||
"wheelUp", "wheelLeft", "wheelRight"}
|
|
||||||
mouseBool bool
|
|
||||||
)
|
|
||||||
|
|
||||||
for i := 0; i < len(mArr); i++ {
|
|
||||||
if key == mArr[i] {
|
|
||||||
mouseBool = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(key) > 1 && !mouseBool {
|
|
||||||
key = strconv.Itoa(int(Keycode[key]))
|
|
||||||
}
|
|
||||||
|
|
||||||
geve := addEvent(key)
|
|
||||||
// defer C.free(unsafe.Pointer(cs))
|
|
||||||
return geve == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddEvents add global event hook
|
|
||||||
//
|
|
||||||
// hook.AddEvents("q")
|
|
||||||
// hook.AddEvents("q", "ctrl")
|
|
||||||
// hook.AddEvents("q", "ctrl", "shift")
|
|
||||||
func AddEvents(key string, arr ...string) bool {
|
|
||||||
s := Start()
|
|
||||||
// defer End()
|
|
||||||
|
|
||||||
ct := false
|
|
||||||
k := 0
|
|
||||||
for {
|
|
||||||
e := <-s
|
|
||||||
|
|
||||||
l := len(arr)
|
|
||||||
if l > 0 {
|
|
||||||
for i := 0; i < l; i++ {
|
|
||||||
ukey := Keycode[arr[i]]
|
|
||||||
|
|
||||||
if e.Kind == KeyHold && e.Keycode == ukey {
|
|
||||||
k++
|
|
||||||
}
|
|
||||||
|
|
||||||
if k == l {
|
|
||||||
ct = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if e.Kind == KeyUp && e.Keycode == ukey {
|
|
||||||
if k > 0 {
|
|
||||||
k--
|
|
||||||
}
|
|
||||||
// time.Sleep(10 * time.Microsecond)
|
|
||||||
ct = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ct = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if ct && e.Kind == KeyUp && e.Keycode == Keycode[key] {
|
|
||||||
End()
|
|
||||||
// k = 0
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddMouse add mouse event hook
|
|
||||||
//
|
|
||||||
// mouse arguments: left, center, right, wheelDown, wheelUp,
|
|
||||||
// wheelLeft, wheelRight.
|
|
||||||
//
|
|
||||||
// hook.AddMouse("left")
|
|
||||||
// hook.AddMouse("left", 100, 100)
|
|
||||||
func AddMouse(btn string, x ...int16) bool {
|
|
||||||
s := Start()
|
|
||||||
ukey := MouseMap[btn]
|
|
||||||
|
|
||||||
ct := false
|
|
||||||
for {
|
|
||||||
e := <-s
|
|
||||||
|
|
||||||
if len(x) > 1 {
|
|
||||||
if e.Kind == MouseMove && e.X == x[0] && e.Y == x[1] {
|
|
||||||
ct = true
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ct = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if ct && e.Kind == MouseDown && e.Button == ukey {
|
|
||||||
End()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddMousePos add listen mouse event pos hook
|
|
||||||
func AddMousePos(x, y int16) bool {
|
|
||||||
s := Start()
|
|
||||||
|
|
||||||
for {
|
|
||||||
e := <-s
|
|
||||||
if e.Kind == MouseMove && e.X == x && e.Y == y {
|
|
||||||
End()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
@ -5,7 +5,8 @@
|
|||||||
/* Python versions under 2.5 don't support this macro, but it's not
|
/* Python versions under 2.5 don't support this macro, but it's not
|
||||||
* terribly difficult to replicate: */
|
* terribly difficult to replicate: */
|
||||||
#ifndef PyModule_AddIntMacro
|
#ifndef PyModule_AddIntMacro
|
||||||
#define PyModule_AddIntMacro(module, macro) PyModule_AddIntConstant(module, #macro, macro)
|
#define PyModule_AddIntMacro(module, macro) \
|
||||||
|
PyModule_AddIntConstant(module, #macro, macro)
|
||||||
#endif /* PyModule_AddIntMacro */
|
#endif /* PyModule_AddIntMacro */
|
||||||
|
|
||||||
#if !defined(IS_MACOSX) && defined(__APPLE__) && defined(__MACH__)
|
#if !defined(IS_MACOSX) && defined(__APPLE__) && defined(__MACH__)
|
||||||
|
@ -73,8 +73,10 @@ struct _MEvent {
|
|||||||
|
|
||||||
typedef struct _MEvent MEvent;
|
typedef struct _MEvent MEvent;
|
||||||
// typedef MMBitmap *MMBitmapRef;
|
// typedef MMBitmap *MMBitmapRef;
|
||||||
|
|
||||||
MEvent mEvent;
|
MEvent mEvent;
|
||||||
|
|
||||||
|
|
||||||
bool loggerProc(unsigned int level, const char *format, ...) {
|
bool loggerProc(unsigned int level, const char *format, ...) {
|
||||||
bool status = false;
|
bool status = false;
|
||||||
|
|
||||||
|
@ -1,113 +0,0 @@
|
|||||||
// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
hook "github.com/robotn/gohook"
|
|
||||||
)
|
|
||||||
|
|
||||||
func addEvent() {
|
|
||||||
fmt.Println("--- Please press ctrl + shift + q ---")
|
|
||||||
ok := hook.AddEvents("q", "ctrl", "shift")
|
|
||||||
if ok {
|
|
||||||
fmt.Println("add events...")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("--- Please press w---")
|
|
||||||
ok = hook.AddEvents("w")
|
|
||||||
if ok {
|
|
||||||
fmt.Println("add events")
|
|
||||||
}
|
|
||||||
|
|
||||||
// start hook
|
|
||||||
s := hook.Start()
|
|
||||||
// end hook
|
|
||||||
defer hook.End()
|
|
||||||
|
|
||||||
for ev := range s {
|
|
||||||
fmt.Println("hook: ", ev)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func addMouse() {
|
|
||||||
fmt.Println("--- Please press left mouse button ---")
|
|
||||||
ok := hook.AddMouse("left")
|
|
||||||
if ok {
|
|
||||||
fmt.Println("add mouse...")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("--- Please press left mouse button and move mosue to 100,100 ---")
|
|
||||||
ok = hook.AddMouse("left", 100, 100)
|
|
||||||
if ok {
|
|
||||||
fmt.Println("add mouse and move to 100,100 ...")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("--- Please move mosue to 100,100 ---")
|
|
||||||
ok = hook.AddMousePos(100, 100)
|
|
||||||
if ok {
|
|
||||||
fmt.Println(" move mouse to 100,100 ...")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func add() {
|
|
||||||
fmt.Println("--- Please press v---")
|
|
||||||
eve := hook.AddEvent("v")
|
|
||||||
|
|
||||||
if eve {
|
|
||||||
fmt.Println("--- You press v---", "v")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("--- Please press k---")
|
|
||||||
keve := hook.AddEvent("k")
|
|
||||||
if keve {
|
|
||||||
fmt.Println("--- You press k---", "k")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("--- Please press f1---")
|
|
||||||
feve := hook.AddEvent("f1")
|
|
||||||
if feve {
|
|
||||||
fmt.Println("You press...", "f1")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func event() {
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Global event listener
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
add()
|
|
||||||
|
|
||||||
fmt.Println("--- Please press left mouse button---")
|
|
||||||
mleft := hook.AddEvent("mleft")
|
|
||||||
if mleft {
|
|
||||||
fmt.Println("--- You press left mouse button---", "mleft")
|
|
||||||
}
|
|
||||||
|
|
||||||
mright := hook.AddEvent("mright")
|
|
||||||
if mright {
|
|
||||||
fmt.Println("--- You press right mouse button---", "mright")
|
|
||||||
}
|
|
||||||
|
|
||||||
// stop AddEvent
|
|
||||||
// hook.StopEvent()
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("test begin...")
|
|
||||||
|
|
||||||
addEvent()
|
|
||||||
|
|
||||||
addMouse()
|
|
||||||
|
|
||||||
event()
|
|
||||||
}
|
|
@ -6,15 +6,6 @@ import (
|
|||||||
hook "github.com/robotn/gohook"
|
hook "github.com/robotn/gohook"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
|
||||||
registerEvent()
|
|
||||||
|
|
||||||
base()
|
|
||||||
|
|
||||||
add()
|
|
||||||
addMouse()
|
|
||||||
}
|
|
||||||
|
|
||||||
func registerEvent() {
|
func registerEvent() {
|
||||||
fmt.Println("--- Please press ctrl + shift + q to stop hook ---")
|
fmt.Println("--- Please press ctrl + shift + q to stop hook ---")
|
||||||
hook.Register(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) {
|
hook.Register(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) {
|
||||||
@ -24,25 +15,7 @@ func registerEvent() {
|
|||||||
|
|
||||||
fmt.Println("--- Please press w ---")
|
fmt.Println("--- Please press w ---")
|
||||||
hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) {
|
hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) {
|
||||||
fmt.Println("KeyDown: ", "w-")
|
fmt.Println("w-")
|
||||||
})
|
|
||||||
|
|
||||||
hook.Register(hook.KeyUp, []string{"w"}, func(e hook.Event) {
|
|
||||||
fmt.Println("KeyUp: ", "w")
|
|
||||||
})
|
|
||||||
|
|
||||||
s := hook.Start()
|
|
||||||
<-hook.Process(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func addMouse() {
|
|
||||||
fmt.Println("--- Please press left mouse button to see it's position and the right mouse button to exit ---")
|
|
||||||
hook.Register(hook.MouseDown, []string{}, func(e hook.Event) {
|
|
||||||
if e.Button == hook.MouseMap["left"] {
|
|
||||||
fmt.Printf("mouse left @ %v - %v\n", e.X, e.Y)
|
|
||||||
} else if e.Button == hook.MouseMap["right"] {
|
|
||||||
hook.End()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
s := hook.Start()
|
s := hook.Start()
|
||||||
@ -77,8 +50,13 @@ func base() {
|
|||||||
|
|
||||||
for ev := range evChan {
|
for ev := range evChan {
|
||||||
fmt.Println("hook: ", ev)
|
fmt.Println("hook: ", ev)
|
||||||
if ev.Keychar == 'q' {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
registerEvent()
|
||||||
|
|
||||||
|
base()
|
||||||
|
|
||||||
|
add()
|
||||||
|
}
|
||||||
|
7
go.mod
7
go.mod
@ -1,8 +1,5 @@
|
|||||||
module github.com/robotn/gohook
|
module github.com/robotn/gohook
|
||||||
|
|
||||||
go 1.17
|
go 1.13
|
||||||
|
|
||||||
require (
|
require github.com/vcaesar/tt v0.11.0
|
||||||
github.com/vcaesar/keycode v0.10.1
|
|
||||||
github.com/vcaesar/tt v0.20.1
|
|
||||||
)
|
|
||||||
|
6
go.sum
6
go.sum
@ -1,4 +1,2 @@
|
|||||||
github.com/vcaesar/keycode v0.10.1 h1:0DesGmMAPWpYTCYddOFiCMKCDKgNnwiQa2QXindVUHw=
|
github.com/vcaesar/tt v0.11.0 h1:obQecjgbnAxxC6OYGY6yDvhGRW2PR5wD8Ma2uJH3WGA=
|
||||||
github.com/vcaesar/keycode v0.10.1/go.mod h1:JNlY7xbKsh+LAGfY2j4M3znVrGEm5W1R8s/Uv6BJcfQ=
|
github.com/vcaesar/tt v0.11.0/go.mod h1:GHPxQYhn+7OgKakRusH7KJ0M5MhywoeLb8Fcffs/Gtg=
|
||||||
github.com/vcaesar/tt v0.20.1 h1:D/jUeeVCNbq3ad8M7hhtB3J9x5RZ6I1n1eZ0BJp7M+4=
|
|
||||||
github.com/vcaesar/tt v0.20.1/go.mod h1:cH2+AwGAJm19Wa6xvEa+0r+sXDJBT0QgNQey6mwqLeU=
|
|
||||||
|
23
hook.go
23
hook.go
@ -32,7 +32,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Version get the gohook version
|
// Version get the gohook version
|
||||||
Version = "v0.40.0.123, Sierra Nevada!"
|
Version = "v0.30.4.100, Sierra Nevada!"
|
||||||
|
|
||||||
// HookEnabled honk enable status
|
// HookEnabled honk enable status
|
||||||
HookEnabled = 1 // iota
|
HookEnabled = 1 // iota
|
||||||
@ -93,11 +93,9 @@ var (
|
|||||||
lck sync.RWMutex
|
lck sync.RWMutex
|
||||||
|
|
||||||
pressed = make(map[uint16]bool, 256)
|
pressed = make(map[uint16]bool, 256)
|
||||||
uppressed = make(map[uint16]bool, 256)
|
|
||||||
used = []int{}
|
used = []int{}
|
||||||
|
|
||||||
keys = map[int][]uint16{}
|
keys = map[int][]uint16{}
|
||||||
upkeys = map[int][]uint16{}
|
|
||||||
cbs = map[int]func(Event){}
|
cbs = map[int]func(Event){}
|
||||||
events = map[uint8][]int{}
|
events = map[uint8][]int{}
|
||||||
)
|
)
|
||||||
@ -118,17 +116,12 @@ func Register(when uint8, cmds []string, cb func(Event)) {
|
|||||||
key := len(used)
|
key := len(used)
|
||||||
used = append(used, key)
|
used = append(used, key)
|
||||||
tmp := []uint16{}
|
tmp := []uint16{}
|
||||||
uptmp := []uint16{}
|
|
||||||
|
|
||||||
for _, v := range cmds {
|
for _, v := range cmds {
|
||||||
if when == KeyUp {
|
|
||||||
uptmp = append(uptmp, Keycode[v])
|
|
||||||
}
|
|
||||||
tmp = append(tmp, Keycode[v])
|
tmp = append(tmp, Keycode[v])
|
||||||
}
|
}
|
||||||
|
|
||||||
keys[key] = tmp
|
keys[key] = tmp
|
||||||
upkeys[key] = uptmp
|
|
||||||
cbs[key] = cb
|
cbs[key] = cb
|
||||||
events[when] = append(events[when], key)
|
events[when] = append(events[when], key)
|
||||||
// return
|
// return
|
||||||
@ -141,7 +134,6 @@ func Process(evChan <-chan Event) (out chan bool) {
|
|||||||
for ev := range evChan {
|
for ev := range evChan {
|
||||||
if ev.Kind == KeyDown || ev.Kind == KeyHold {
|
if ev.Kind == KeyDown || ev.Kind == KeyHold {
|
||||||
pressed[ev.Keycode] = true
|
pressed[ev.Keycode] = true
|
||||||
uppressed[ev.Keycode] = true
|
|
||||||
} else if ev.Kind == KeyUp {
|
} else if ev.Kind == KeyUp {
|
||||||
pressed[ev.Keycode] = false
|
pressed[ev.Keycode] = false
|
||||||
}
|
}
|
||||||
@ -153,12 +145,6 @@ func Process(evChan <-chan Event) (out chan bool) {
|
|||||||
|
|
||||||
if allPressed(pressed, keys[v]...) {
|
if allPressed(pressed, keys[v]...) {
|
||||||
cbs[v](ev)
|
cbs[v](ev)
|
||||||
} else if ev.Kind == KeyUp {
|
|
||||||
//uppressed[ev.Keycode] = true
|
|
||||||
if allPressed(uppressed, upkeys[v]...) {
|
|
||||||
uppressed = make(map[uint16]bool, 256)
|
|
||||||
cbs[v](ev)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,7 +253,6 @@ func End() {
|
|||||||
close(ev)
|
close(ev)
|
||||||
|
|
||||||
pressed = make(map[uint16]bool, 256)
|
pressed = make(map[uint16]bool, 256)
|
||||||
uppressed = make(map[uint16]bool, 256)
|
|
||||||
used = []int{}
|
used = []int{}
|
||||||
|
|
||||||
keys = map[int][]uint16{}
|
keys = map[int][]uint16{}
|
||||||
@ -275,8 +260,8 @@ func End() {
|
|||||||
events = map[uint8][]int{}
|
events = map[uint8][]int{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddEvent add the block event listener
|
// AddEvent add event listener
|
||||||
func addEvent(key string) int {
|
func AddEvent(key string) int {
|
||||||
cs := C.CString(key)
|
cs := C.CString(key)
|
||||||
defer C.free(unsafe.Pointer(cs))
|
defer C.free(unsafe.Pointer(cs))
|
||||||
|
|
||||||
@ -286,7 +271,7 @@ func addEvent(key string) int {
|
|||||||
return geve
|
return geve
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopEvent stop the block event listener
|
// StopEvent stop event listener
|
||||||
func StopEvent() {
|
func StopEvent() {
|
||||||
C.stop_event()
|
C.stop_event()
|
||||||
}
|
}
|
||||||
|
106
keycode.go
106
keycode.go
@ -10,13 +10,103 @@
|
|||||||
|
|
||||||
package hook
|
package hook
|
||||||
|
|
||||||
import "github.com/vcaesar/keycode"
|
type uMap map[string]uint16
|
||||||
|
|
||||||
// MouseMap defines the robotgo hook mouse's code map
|
// MouseMap robotgo hook mouse's code map
|
||||||
var MouseMap = keycode.MouseMap
|
var MouseMap = uMap{
|
||||||
|
"left": 1,
|
||||||
|
"right": 2,
|
||||||
|
"center": 3,
|
||||||
|
"wheelDown": 4,
|
||||||
|
"wheelUp": 5,
|
||||||
|
"wheelLeft": 6,
|
||||||
|
"wheelRight": 7,
|
||||||
|
}
|
||||||
|
|
||||||
// Keycode defines the robotgo hook key's code map
|
// Keycode robotgo hook key's code map
|
||||||
var Keycode = keycode.Keycode
|
var Keycode = uMap{
|
||||||
|
"`": 41,
|
||||||
// Special defines the special key map
|
"1": 2,
|
||||||
var Special = keycode.Special
|
"2": 3,
|
||||||
|
"3": 4,
|
||||||
|
"4": 5,
|
||||||
|
"5": 6,
|
||||||
|
"6": 7,
|
||||||
|
"7": 8,
|
||||||
|
"8": 9,
|
||||||
|
"9": 10,
|
||||||
|
"0": 11,
|
||||||
|
"-": 12,
|
||||||
|
"+": 13,
|
||||||
|
//
|
||||||
|
"q": 16,
|
||||||
|
"w": 17,
|
||||||
|
"e": 18,
|
||||||
|
"r": 19,
|
||||||
|
"t": 20,
|
||||||
|
"y": 21,
|
||||||
|
"u": 22,
|
||||||
|
"i": 23,
|
||||||
|
"o": 24,
|
||||||
|
"p": 25,
|
||||||
|
"[": 26,
|
||||||
|
"]": 27,
|
||||||
|
"\\": 43,
|
||||||
|
//
|
||||||
|
"a": 30,
|
||||||
|
"s": 31,
|
||||||
|
"d": 32,
|
||||||
|
"f": 33,
|
||||||
|
"g": 34,
|
||||||
|
"h": 35,
|
||||||
|
"j": 36,
|
||||||
|
"k": 37,
|
||||||
|
"l": 38,
|
||||||
|
";": 39,
|
||||||
|
"'": 40,
|
||||||
|
//
|
||||||
|
"z": 44,
|
||||||
|
"x": 45,
|
||||||
|
"c": 46,
|
||||||
|
"v": 47,
|
||||||
|
"b": 48,
|
||||||
|
"n": 49,
|
||||||
|
"m": 50,
|
||||||
|
",": 51,
|
||||||
|
".": 52,
|
||||||
|
"/": 53,
|
||||||
|
//
|
||||||
|
"f1": 59,
|
||||||
|
"f2": 60,
|
||||||
|
"f3": 61,
|
||||||
|
"f4": 62,
|
||||||
|
"f5": 63,
|
||||||
|
"f6": 64,
|
||||||
|
"f7": 65,
|
||||||
|
"f8": 66,
|
||||||
|
"f9": 67,
|
||||||
|
"f10": 68,
|
||||||
|
"f11": 69,
|
||||||
|
"f12": 70,
|
||||||
|
// more
|
||||||
|
"esc": 1,
|
||||||
|
"delete": 14,
|
||||||
|
"tab": 15,
|
||||||
|
"ctrl": 29,
|
||||||
|
"control": 29,
|
||||||
|
"alt": 56,
|
||||||
|
"space": 57,
|
||||||
|
"shift": 42,
|
||||||
|
"rshift": 54,
|
||||||
|
"enter": 28,
|
||||||
|
//
|
||||||
|
"cmd": 3675,
|
||||||
|
"command": 3675,
|
||||||
|
"rcmd": 3676,
|
||||||
|
"ralt": 3640,
|
||||||
|
//
|
||||||
|
"up": 57416,
|
||||||
|
"down": 57424,
|
||||||
|
"left": 57419,
|
||||||
|
"right": 57421,
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user