input

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package input provides a set of useful methods that helps on input based interaction with an associated android device. All input interactions are either based on "adb shell input" command or via sending raw input commands to input device directly.

Following are the list of supported input mechanisms :

  • Touch screen based input
  • Key press based input
  • Simple text input

Touch screen based input operations provide following features:

  • Perform single touch on any screen coordinate
  • Draw multi point gesture on real device or emulator
  • Perform swipe operation between any two points in the screen
  • Perform generic swipe operations such as swipe up/down/left/right on screen
  • Determine devices touch input device path
  • Send raw touch input commands to touch input device

Key press based input operations provide following features:

  • Send any key press code for any number of times
  • Provides generic key press methods such as home/power/back...

Text input operations provide following features:

  • Allows you to enter simple text on devices focused input area

Currently text input operation is very limited and can not insert any special characters or unicode characters. This limitation is imposed by "adb shell input text" command.

Index

Constants

View Source
const (
	EV_ABS                  = 3   // ABS Event
	EV_SYN                  = 0   // Sync Event
	EV_KEY                  = 1   // Key event
	BTN_TOUCH               = 330 // Touch event
	BTN_TOOL_FINGER         = 325 // Finger event
	DOWN                    = 1   // Touch down event
	UP                      = 0   // Touch up event
	ABS_MT_TRACKING_ID      = 57  // ID of the touch (important for multi-touch reports)
	ABS_MT_TOUCH_MAJOR      = 48  // Touch size in pixels
	ABS_MT_POSITION_X       = 53  // X coordinate of the touch
	ABS_X                   = 0   // X coordinate of touch in emulator
	ABS_MT_POSITION_Y       = 54  // Y coordinate of the touch
	ABS_Y                   = 1   // Y coordinate of touch in emulator
	ABS_MT_PRESSURE         = 58  // Pressure of the touch
	SYN_MT_REPORT           = 2   // End of separate touch data
	SYN_REPORT              = 0   // End of report
	DEFAULT_TOUCH_ID        = 0   // Default touch point id
	DEFAULT_PRESSURE        = 50  // Touch pressure default value
	DEFAULT_FINGER_TIP_SIZE = 5   // Default touch finger tip size
)
View Source
const (
	MENU_KEY        = 1  // Menu key code
	HOME_KEY        = 3  // Home key code
	BACK_KEY        = 4  // Back key code
	CALL_KEY        = 5  // Cll key code
	ENDCALL_KEY     = 6  // End call key code
	UP_KEY          = 19 // Up key code
	DOWN_KEY        = 20 // Down key code
	LEFT_KEY        = 21 // Left key code
	RIGHT_KEY       = 22 // Right key code
	VOLUME_UP_KEY   = 24 // Volume up key code
	VOLUME_DOWN_KEY = 25 // Volume down key code
	POWER_KEY       = 26 // Power key code
	CAMERA_KEY      = 27 // Camera key code
	ENTER_KEY       = 66 // Enter key code
	DEL_KEY         = 67 // Del key code
)

Variables

This section is empty.

Functions

This section is empty.

Types

type InputManager

type InputManager struct {
	TouchScreen TouchScreen // Associated touch screen input
	Key         Key         // Associated key input
	TextInput   TextInput   // Associated text input
	// contains filtered or unexported fields
}

InputManager struct holds all type of supported device input interfaces such as touch screen input interface to operate touch based inputes, key input interface to operate on key press inputs, text input interface to insert text on selected text box (text input function is very limited at this point, does not supports unicode and any special characters and its limited by "adb shell input text capabilites").

func NewInputManager

func NewInputManager(dev device.Device) InputManager

NewInputManager method returns a new InputManager struct and associates it with given device.

type Key

type Key struct {
	// contains filtered or unexported fields
}

Key struct defines a key input subsystem associated with a device.

func NewKey

func NewKey(dev device.Device) Key

NewKey method returns a new Key struct associated with given device.

func (Key) Press

func (key Key) Press(code int, count int) error

Press method performs a key press event based on given key code, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressBack

func (key Key) PressBack(count int) error

PressBack method performs a back key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressCall

func (key Key) PressCall(count int) error

PressCall method performs a call key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressCamera

func (key Key) PressCamera(count int) error

PressCamera method performs a camera key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressDelete

func (key Key) PressDelete(count int) error

PressDelete method performs a delete key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressDown

func (key Key) PressDown(count int) error

PressDown method performs a down key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressEndCall

func (key Key) PressEndCall(count int) error

PressEndCall method performs a end call key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressEnter

func (key Key) PressEnter(count int) error

PressEnter method performs a enter key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressHome

func (key Key) PressHome(count int) error

PressHome method performs a home key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressLeft

func (key Key) PressLeft(count int) error

PressLeft method performs a left key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressMenu

func (key Key) PressMenu(count int) error

PressMenu method performs a menu key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressPower

func (key Key) PressPower(count int) error

PressPower method performs a power key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressRight

func (key Key) PressRight(count int) error

PressRight method performs a right key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressUp

func (key Key) PressUp(count int) error

PressUp method performs a up key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressVolumeDown

func (key Key) PressVolumeDown(count int) error

PressVolumeDown method performs a volume down key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

func (Key) PressVolumeUp

func (key Key) PressVolumeUp(count int) error

PressVolumeUp method performs a volume up key press event, this operation is repeated based on the count parameter. It returns error on adb operation failure.

type TextInput

type TextInput struct {
	// contains filtered or unexported fields
}

TextInput struct represents a text input subsystem for associated device.

func NewTextInput

func NewTextInput(dev device.Device) TextInput

NewTextInput method returns a new TextInput struct which is associated with given device.

func (TextInput) EnterText

func (ti TextInput) EnterText(text string)

EnterText method enters text on selected input area. Input area must be selected previously. Functionality of this method is very limited and does not support any unicode aharacters or any special characters.

type TouchScreen

type TouchScreen struct {
	// contains filtered or unexported fields
}

TouchScreen struct represensts touch input susbystem for associated device.

func NewTouchScreen

func NewTouchScreen(dev device.Device) TouchScreen

NewTouchScreen method returns a new TouchScreen and associates it with given device.

func (TouchScreen) DrawGesture

func (ts TouchScreen) DrawGesture(points geometry.Points, delay int) error

DrawGesture method allows you to draw a continious gesture on device view. It takes a set of points and a delay parameter, gesture is drawn based on given set of points and each point is iterated after specific delay. Please note that the delay here is in milliseconds. It returns error on adb operation errors. Gesture is drawn based on multitouch protocol v2 events.

func (TouchScreen) DrawGestureEmulator

func (ts TouchScreen) DrawGestureEmulator(points geometry.Points, delay int) error

DrawGestureEmulator method allows you to draw gesture on emulator device. Emulator devices are generally single touch and operates on different touch protocol than of multitouch v2 protocol. This method takes a set of points and a delay parameter, gesture is drawn based on given set of points and iterated one by one with specific delay in between. Please note tha value of delay is in milliseconds. It returns error on adb operation failure.

func (TouchScreen) GetTouchInputDevice

func (ts TouchScreen) GetTouchInputDevice() (string, error)

GetTouchInputDevice method is used to determine correct touch input device path on associated android device. It returns error on adb operation failure or if device path can not be determined for any reason.

func (TouchScreen) RawMovePoint

func (ts TouchScreen) RawMovePoint(dev string, x int, y int, id int, pressure int, size int) error

RawMovePoint method allows you to move a gesture point on device screen. This can be used to draw gesture with different parameters than of defauls. Please note that users need to send sync signals by them self, check DrawGesture method implementation regarding this, if user specific gesture method method implementation is required. This method takes x and y coordinates of new gesture point along with touch point id, touch pressure and touch finger tip size and touch device path. It returns error on adb operation failure.

func (TouchScreen) RawMovePointEmulator

func (ts TouchScreen) RawMovePointEmulator(dev string, x int, y int) error

RawMovePointEmulator method allows you to move a gesture point on emulator screen. This can be used to draw gesture with different parameters than of defauls. Please note that users need to send sync signals by them self, check DrawGestureEmulator method implementation regarding this, if user specific gesture method method implementation is required. This method takes x and y coordinates of new gesture point along with touch device path and returns error on adb operation failure.

func (TouchScreen) RawSendEvent

func (ts TouchScreen) RawSendEvent(dev string, eventType int, event int, value int) error

RawSendEvent sends raw touch input event on given touch device, it takes event type, event code and event value as parameter and returns error on adb operation failure. make sure you are using correct device path for touch device, and can be obtailed easily by GetTouchInputDevice method.

func (TouchScreen) Swipe

func (ts TouchScreen) Swipe(x1 int, y1 int, x2 int, y2 int, delay int) error

Swipe method performs touch swipe operation from given (x1, y1) coordinate to (x2, y2) coordinate with specified delay. It returns error on adb operation failure.

func (TouchScreen) SwipeDown

func (ts TouchScreen) SwipeDown(count int) error

SwipeDown method performs touch swipe down (top --> bottom) operation for a number of times defined by given count parameter. It returns error on adb operation failure.

func (TouchScreen) SwipeLeft

func (ts TouchScreen) SwipeLeft(count int) error

SwipeLeft method performs touch swipe left (right --> left) operation for a number of times defined by given count parameter. It returns error on adb operation failure.

func (TouchScreen) SwipeRight

func (ts TouchScreen) SwipeRight(count int) error

SwipeRight method performs touch swipe right (right --> left) operation for a number of times defined by given count parameter. It returns error on adb operation failure.

func (TouchScreen) SwipeUp

func (ts TouchScreen) SwipeUp(count int) error

SwipeUp method performs touch swipe up (bottom --> top) operation for a number of times defined by given count parameter. It returns error on adb operation failure.

func (TouchScreen) Tap

func (ts TouchScreen) Tap(x int, y int) error

Tap method performs a touch operation on specified (x,y) coordinate. It returns error on adb operation failure.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL