mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 00:47:09 +00:00
feat: support sending modifier keys (#18)
Co-authored-by: E44 <129310925+programmer-44@users.noreply.github.com>
This commit is contained in:
@@ -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()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user