-
Notifications
You must be signed in to change notification settings - Fork 7
/
cursor_windows.go
53 lines (46 loc) · 1.04 KB
/
cursor_windows.go
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
package duitdraw
import (
"errors"
"fmt"
"image"
"os"
"github.com/as/cursor"
"github.com/as/ms/win"
)
// This sets the mouse cursor relative to the current window.
//
// TODO: There seems to be an offset, maybe it's related to the window borders.
// You can calculate your offset by pressing the tab key and clicking with the mouse.
// Log coordinates of MouseMove and mouse.Event (in display.go) and substract the results.
//
// Source: github.com/as/a/mouse_windows.go
var (
winfd win.Window
winfderr error
cursorOffset = image.Point{4, 4}
)
func tryWindow() {
if winfd != 0 && winfderr == nil {
return
}
winfd, winfderr = win.Open(os.Getpid())
}
func moveTo(pt image.Point) error {
tryWindow()
abs, err := winfd.Client()
if err != nil {
winfderr = err
return err
}
pt = pt.Add(abs.Min).Sub(cursorOffset)
if cursor.MoveTo(pt) == false {
return fmt.Errorf("move cursor failed")
}
return nil
}
func setCursor(c *Cursor) error {
if c != nil {
return errors.New("duitdraw: SetCursor is not implemented")
}
return nil
}