Commit ce3399ec authored by Amos Wenger's avatar Amos Wenger

Add a bunch of syscalls

parent 1f7eb815
Pipeline #13537 failed with stage
in 12 seconds
module github.com/itchio/ox
require (
github.com/itchio/wharf v0.0.0-20181213155255-5c074d8f87a4
github.com/pkg/errors v0.8.1
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
)
github.com/itchio/wharf v0.0.0-20181213155255-5c074d8f87a4 h1:+lsGaAGakbMki2lTQWUNkGy91RMx17R58RH4GnqeRsU=
github.com/itchio/wharf v0.0.0-20181213155255-5c074d8f87a4/go.mod h1:+POTUNOKzhCiFy3BM0Qb7RHLTHazlOcypTnt7QbOeks=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
......@@ -16,6 +16,10 @@ var (
procShowWindow = moduser32.NewProc("ShowWindow")
procIsWindowVisible = moduser32.NewProc("IsWindowVisible")
procSwitchToThisWindow = moduser32.NewProc("SwitchToThisWindow")
procFindWindow = moduser32.NewProc("FindWindowW")
procSendInput = moduser32.NewProc("SendInput")
procGetWindowRect = moduser32.NewProc("GetWindowRect")
procGetSystemMetrics = moduser32.NewProc("GetSystemMetrics")
)
func EnumWindows(
......@@ -125,3 +129,180 @@ func SwitchToThisWindow(
0,
)
}
func FindWindow(cls string, win string) (syscall.Handle, error) {
r0, _, e1 := syscall.Syscall(
procFindWindow.Addr(), 2,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(cls))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(win))),
0,
)
var err error
if r0 == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return syscall.Handle(r0), err
}
func FindWindowByClass(cls string) (syscall.Handle, error) {
r0, _, e1 := syscall.Syscall(
procFindWindow.Addr(), 2,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(cls))),
0,
0,
)
var err error
if r0 == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return syscall.Handle(r0), err
}
type INPUT struct {
Type uint32
Input MOUSEINPUT
}
var (
INPUT_MOUSE uint32 = 0
INPUT_KEYBOARD uint32 = 1
INPUT_HARDWARE uint32 = 2
)
func (i *INPUT) SetKeyboardInput(ki KEYBDINPUT) {
i.Type = INPUT_KEYBOARD
var mip = (&i.Input)
*mip = MOUSEINPUT{}
var p = (*KEYBDINPUT)((unsafe.Pointer)(mip))
*p = ki
}
func (i *INPUT) SetMouseInput(mi MOUSEINPUT) {
i.Type = INPUT_MOUSE
var mip = (&i.Input)
*mip = mi
}
type MOUSEINPUT struct {
X int32
Y int32
MouseData uint32
Flags uint32
Time uint32
ExtraInfo *uint32
}
type KEYBDINPUT struct {
Vk uint16
Scan uint16
Flags uint32
Time uint32
ExtraInfo *uint32
}
type HARDWAREINPUT struct {
UMsg uint32
ParamL int16
ParamH int16
}
var (
KEYEVENTF_EXTENDEDKEY uint32 = 0x0001
KEYEVENTF_KEYUP uint32 = 0x0002
KEYEVENTF_UNICODE uint32 = 0x0004
KEYEVENTF_SCANCODE uint32 = 0x0008
)
var (
MOUSEEVENTF_ABSOLUTE uint32 = 0x8000
MOUSEEVENTF_HWHEEL uint32 = 0x1000
MOUSEEVENTF_MOVE uint32 = 0x0001
MOUSEEVENTF_MOVE_NOCOALESCE uint32 = 0x2000
MOUSEEVENTF_LEFTDOWN uint32 = 0x0002
MOUSEEVENTF_LEFTUP uint32 = 0x0004
MOUSEEVENTF_RIGHTDOWN uint32 = 0x0008
MOUSEEVENTF_RIGHTUP uint32 = 0x0010
MOUSEEVENTF_MIDDLEDOWN uint32 = 0x0020
MOUSEEVENTF_MIDDLEUP uint32 = 0x0040
MOUSEEVENTF_VIRTUALDESK uint32 = 0x4000
MOUSEEVENTF_WHEEL uint32 = 0x0800
MOUSEEVENTF_XDOWN uint32 = 0x0080
MOUSEEVENTF_XUP uint32 = 0x0100
)
func SendMouseInput(mi MOUSEINPUT) (err error) {
var i INPUT
i.SetMouseInput(mi)
return SendInput(i)
}
func SendKeyboardInput(ki KEYBDINPUT) (err error) {
var i INPUT
i.SetKeyboardInput(ki)
return SendInput(i)
}
func SendInput(input INPUT) (err error) {
r0, _, e1 := syscall.Syscall(
procSendInput.Addr(), 3,
1,
uintptr(unsafe.Pointer(&input)),
unsafe.Sizeof(INPUT{}),
)
if r0 == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
type RECT struct {
Left int32
Top int32
Right int32
Bottom int32
}
func GetWindowRect(hwnd syscall.Handle) (rect RECT, err error) {
r0, _, e1 := syscall.Syscall(
procGetWindowRect.Addr(), 2,
uintptr(hwnd),
uintptr(unsafe.Pointer(&rect)),
0,
)
if r0 == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
var (
SM_CXSCREEN int = 0
SM_CYSCREEN = 1
)
func GetSystemMetrics(nIndex int) (ret int) {
r0, _, _ := syscall.Syscall(
procGetSystemMetrics.Addr(), 1,
uintptr(nIndex),
0, 0,
)
ret = int(r0)
return
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment