2023-11-27 10:38:57 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
"time"
|
2023-11-27 11:18:41 +00:00
|
|
|
|
|
|
|
"github.com/micmonay/keybd_event"
|
2023-11-27 10:38:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
kb, err := keybd_event.NewKeyBonding()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// For linux, it is very important to wait 2 seconds
|
|
|
|
if runtime.GOOS == "linux" {
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select keys to be pressed
|
|
|
|
kb.SetKeys(keybd_event.VK_UP)
|
|
|
|
|
|
|
|
// Set shift to be pressed
|
|
|
|
kb.HasSHIFT(false)
|
|
|
|
|
|
|
|
// Press the selected keys
|
|
|
|
err = kb.Launching()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Or you can use Press and Release
|
|
|
|
kb.Press()
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
kb.Release()
|
|
|
|
|
|
|
|
// Here, the program will generate "ABAB" as if they were pressed on the keyboard.
|
|
|
|
}
|