()
| 45 | } |
| 46 | |
| 47 | func 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 | } |
nothing calls this directly
no test coverage detected