feat: support sending modifier keys (#18)

Co-authored-by: E44 <129310925+programmer-44@users.noreply.github.com>
This commit is contained in:
2026-01-19 18:47:53 +01:00
committed by GitHub
parent c8e21a64bf
commit 4d5d9849da
7 changed files with 339 additions and 388 deletions
-42
View File
@@ -11,8 +11,6 @@ import (
"time"
"plg-mudics/shared"
"github.com/micmonay/keybd_event"
)
func GetDeviceIp() (string, error) {
@@ -46,46 +44,6 @@ func GetDeviceMac() (string, error) {
return "", fmt.Errorf("no suitable MAC address found")
}
type KeyAction int
const (
KeyPress KeyAction = iota
KeyRelease
)
type Input struct {
Key int
Action KeyAction
}
func KeyboardInput(inputs []Input) error {
var err error
kb, err := keybd_event.NewKeyBonding()
if err != nil {
return fmt.Errorf("failed to create key bonding: %w", err)
}
for _, input := range inputs {
kb.SetKeys(input.Key)
switch input.Action {
case KeyPress:
err = kb.Press()
case KeyRelease:
err = kb.Release()
}
if err != nil {
return fmt.Errorf("failed to run key event: %w", err)
}
time.Sleep(time.Microsecond * 100)
}
return nil
}
func TakeScreenshot() (string, error) {
tempFilePath := filepath.Join(os.TempDir(), fmt.Sprintf("screenshot_%d.png", time.Now().Unix()))