You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB
Go

1 year ago
package win32api
import (
"errors"
"syscall"
)
func Keybd_event(keyname string, keydown bool) error {
var key int
var down uintptr
if !keydown {
down = KEYEVENTF_KEYUP
}
switch keyname {
case "shift":
key = VK_SHIFT
case "lshift":
key = VK_LSHIFT
case "rshift":
key = VK_RSHIFT
case "a":
key = VK_A
}
user32, err := syscall.LoadLibrary("user32.dll")
if err != nil {
return errors.New("Can't Load User32 API")
}
defer syscall.FreeLibrary(user32)
keyevent, err := syscall.GetProcAddress(syscall.Handle(user32), "keybd_event")
if err != nil {
return errors.New("Can't Load Keybd_event API")
}
syscall.Syscall6(keyevent, 4, uintptr(key), uintptr(key), down, 0, 0, 0)
return nil
}
func Keybd_event_origin(key, keyenv, down, extra uintptr) error {
user32, err := syscall.LoadLibrary("user32.dll")
if err != nil {
return errors.New("Can't Load User32 API")
}
defer syscall.FreeLibrary(user32)
keyevent, err := syscall.GetProcAddress(syscall.Handle(user32), "keybd_event")
if err != nil {
return errors.New("Can't Load Keybd_event API")
}
syscall.Syscall6(keyevent, 4, key, keyenv, down, extra, 0, 0)
return nil
}