// Input the given textual data as keyboard input into the currently focused
// page element.
Input the given textual data as keyboard input into the currently focused
page element.
// Input the given textual data as keyboard input into the currently focused // page element .
func (self *Commands) Type(input interface{}, args *TypeArgs) (string, error) {
	if args == nil {
		args = &TypeArgs{}
	}
	text := typeutil.V(input).String()
	defaults.SetDefaults(args)
	args.KeyDownTime = utils.FudgeDuration(args.KeyDownTime)
	args.KeyDownJitter = utils.FudgeDuration(args.KeyDownJitter)
	args.Delay = utils.FudgeDuration(args.Delay)
	args.DelayJitter = utils.FudgeDuration(args.DelayJitter)
	for _, char := range text {
		if _, err := self.browser.Tab().RPC(`Input`, `dispatchKeyEvent`, map[string]interface{}{
			`type`:     `keyDown`,
			`text`:     string(char),
			`isKeypad`: args.IsKeypad,
		}); err == nil {
			if args.KeyDownTime > 0 {
				time.Sleep(
					args.KeyDownTime + (time.Duration(float64(args.KeyDownJitter)*rand.Float64()) * time.Millisecond),
				)
			}
		} else {
			return ``, err
		}
		if _, err := self.browser.Tab().RPC(`Input`, `dispatchKeyEvent`, map[string]interface{}{
			`type`: `keyUp`,
		}); err != nil {
			return ``, err
		}
		if args.Delay > 0 {
			time.Sleep(
				args.Delay + (time.Duration(float64(args.DelayJitter)*rand.Float64()) * time.Millisecond),
			)
		}
	}
	return text, nil
}
func ( self * Commands ) Type ( input interface { } , args * TypeArgs ) ( string , error ) { if args == nil { args = & TypeArgs { } } text := typeutil . V ( input ) . String ( ) defaults . SetDefaults ( args ) args . KeyDownTime = utils . FudgeDuration ( args . KeyDownTime ) args . KeyDownJitter = utils . FudgeDuration ( args . KeyDownJitter ) args . Delay = utils . FudgeDuration ( args . Delay ) args . DelayJitter = utils . FudgeDuration ( args . DelayJitter ) for _ , char := range text { if _ , err := self . browser . Tab ( ) . RPC ( `Input` , `dispatchKeyEvent` , map [ string ] interface { } { `type` : `keyDown` , `text` : string ( char ) , `isKeypad` : args . IsKeypad , } ) ; err == nil { if args . KeyDownTime > 0 { time . Sleep ( args . KeyDownTime + ( time . Duration ( float64 ( args . KeyDownJitter ) * rand . Float64 ( ) ) * time . Millisecond ) , ) } } else { return `` , err } if _ , err := self . browser . Tab ( ) . RPC ( `Input` , `dispatchKeyEvent` , map [ string ] interface { } { `type` : `keyUp` , } ) ; err != nil { return `` , err } if args . Delay > 0 { time . Sleep ( args . Delay + ( time . Duration ( float64 ( args . DelayJitter ) * rand . Float64 ( ) ) * time . Millisecond ) , ) } } return text , nil }
Input the given textual data as keyboard input into the currently focused
page element.
Input the given textual data as keyboard input into the currently focused page element .
// send the keyDown event // send the keyUp event // simulate the time between key presses