// presses and subsequently releases a key func push(kb *gostwriter.Keyboard, c key.Code) { // pretend to be a slow, puny human // allow for some time between keystrokes wait(200) key, err := kb.Get(c) guard(err) err = key.Push() guard(err) }
func (k *KB) Type(data string) error { // split it strArr := strings.Split(data, "") // prepare the shift key shift, err := k.Keyboard.Get(key.CODE_LEFTSHIFT) if err != nil { return err } defer shift.Release() // process for _, keyStr := range strArr { if k.isSpecialUppercase.MatchString(keyStr) { err = shift.Press() if err != nil { return err } } key, err := k.Keyboard.Get(keyMap[keyStr]) if err != nil { return err } err = key.Push() if err != nil { return err } if shift.IsPressed() { err = shift.Release() if err != nil { return err } } <-time.After(k.Delay) } return nil }