chore(keyboardInput): new api from docs (#4)

This commit is contained in:
2025-11-23 13:02:34 +01:00
committed by GitHub
parent 2767d57a8c
commit cad8f0dc76
2 changed files with 43 additions and 6 deletions
+19 -3
View File
@@ -56,15 +56,31 @@ func OpenPresentation(path string) error {
return nil
}
func KeyboardInput(key int) error {
type KeyAction int
const (
KeyPress KeyAction = iota
KeyRelease
)
func KeyboardInput(key int, action KeyAction) error {
var err error
kb, err := keybd_event.NewKeyBonding()
if err != nil {
return fmt.Errorf("failed to create key bonding: %w", err)
}
kb.SetKeys(key)
if err := kb.Launching(); err != nil {
return fmt.Errorf("failed to launch key event: %w", err)
switch action {
case KeyPress:
err = kb.Press()
case KeyRelease:
err = kb.Release()
}
if err != nil {
return fmt.Errorf("failed to run key event: %w", err)
}
return nil