MCPcopy Create free account
hub / github.com/atomicgo/keyboard / ExampleSimulateKeyPress

Function ExampleSimulateKeyPress

examples_test.go:47–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

45}
46
47func ExampleSimulateKeyPress() {
48 go func() {
49 SimulateKeyPress("Hello") // Simulate key press for every letter in string
50 SimulateKeyPress(keys.Enter) // Simulate key press for Enter
51 SimulateKeyPress(keys.CtrlShiftRight) // Simulate key press for Ctrl+Shift+Right
52 SimulateKeyPress('x') // Simulate key press for a single rune
53 SimulateKeyPress('x', keys.Down, 'a') // Simulate key presses for multiple inputs
54
55 SimulateKeyPress(keys.Escape) // Simulate key press for Escape, which quits the program
56 }()
57
58 Listen(func(key keys.Key) (stop bool, err error) {
59 if key.Code == keys.Escape || key.Code == keys.CtrlC {
60 os.Exit(0) // Exit program on Escape
61 }
62
63 fmt.Println("\r" + key.String()) // Print every key press
64
65 return false, nil // Return false to continue listening
66 })
67}

Callers

nothing calls this directly

Calls 3

SimulateKeyPressFunction · 0.85
ListenFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected