emulate a key press on the android tv device
(keycode common.RemoteKeyCode)
| 80 | |
| 81 | // emulate a key press on the android tv device |
| 82 | func (c *Command) SendKey(keycode common.RemoteKeyCode) error { |
| 83 | err := c.sendConfiguration() |
| 84 | if err != nil { |
| 85 | return err |
| 86 | } |
| 87 | |
| 88 | code := byte(keycode) |
| 89 | press := []byte{1, 2, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, code} |
| 90 | _, err = c.Connection.Write(press) |
| 91 | if err != nil { |
| 92 | return err |
| 93 | } |
| 94 | |
| 95 | // wait 100ms between press and released |
| 96 | time.Sleep(100 * time.Millisecond) |
| 97 | |
| 98 | release := []byte{1, 2, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, code} |
| 99 | _, err = c.Connection.Write(release) |
| 100 | if err != nil { |
| 101 | return err |
| 102 | } |
| 103 | |
| 104 | return nil |
| 105 | } |
| 106 | |
| 107 | // converts a string to a byte array |
| 108 | func text2byte(text string) []byte { |
nothing calls this directly
no test coverage detected