-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.go
More file actions
85 lines (81 loc) · 2.6 KB
/
main.go
File metadata and controls
85 lines (81 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"fmt"
"github.com/lxn/win"
"keyClone/utils"
"log"
)
func executeOp(channel chan *utils.OpElement) {
fmt.Println("KeyClone process started")
lastKeyOp := ""
//var lastKeyOp string
const title = "魔兽世界" // set the window text title
//var currentForceHandle uintptr
//leftButtonPressed := false
//rightButtonPressed := false
hArr, err := utils.FindWindowHandler(title)
if err != nil {
log.Fatal(err)
}
for opElement := range channel {
currentForceHandle := opElement.CurrentWindowHandle
if !utils.IntInArr(int(currentForceHandle), hArr) {
continue
}
if opElement.OpType == 0 { // keyPress
for _, value := range hArr {
value := value
go func() {
if uintptr(value) == currentForceHandle { // current windows's keyStroke
return
}
if opElement.KeyType == 0 && (string(opElement.KeyCode)+"DOWN") != lastKeyOp { // key press down and different with the last key stroke
lastKeyOp = string(opElement.KeyCode) + "DOWN"
utils.PressKeyDown(uintptr(value), uintptr(opElement.KeyCode))
} else if opElement.KeyType == 1 && (string(opElement.KeyCode)+"UP") != lastKeyOp { // key press up and different with the last key stroke
lastKeyOp = string(opElement.KeyCode) + "UP"
utils.PressKeyUp(uintptr(value), uintptr(opElement.KeyCode))
}
}()
}
} else { // mouse wheel
for _, value := range hArr {
value := value
//if opElement.WParam == win.WM_LBUTTONDOWN {
// leftButtonPressed = true
//}
//if opElement.WParam == win.WM_LBUTTONUP {
// leftButtonPressed = false
//}
//if opElement.WParam == win.WM_RBUTTONDOWN {
// rightButtonPressed = true
//}
//if opElement.WParam == win.WM_RBUTTONUP {
// rightButtonPressed = false
//}
go func() {
if uintptr(value) == currentForceHandle {
return
}
wParam := opElement.MouseWParam
if opElement.WParam == win.WM_RBUTTONDOWN || opElement.WParam == win.WM_RBUTTONUP {
return
}
//if leftButtonPressed && opElement.WParam == win.WM_MOUSEMOVE {
// wParam = win.MK_LBUTTON
//}
//if rightButtonPressed && opElement.WParam == win.WM_MOUSEMOVE {
// wParam = win.MK_RBUTTON
//}
utils.PostMessage(uintptr(value), uint32(opElement.WParam), wParam, opElement.MouseLParam) // post mouse wheel, see also https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-mousewheel
}()
}
}
}
}
func main() {
var channel = make(chan *utils.OpElement, 1000)
go executeOp(channel)
go utils.MouseHook(channel)
utils.KeyboardHook(channel, []int{65, 68, 69, 81, 83, 87, 27, 13, 77, 144})
}