Skip to content
This repository has been archived by the owner on Nov 24, 2018. It is now read-only.

First attempt! #379

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,29 @@ export async function getClientRect(client, selector): Promise<ClientRect> {
return JSON.parse(result.result.value) as ClientRect
}

export async function click(client: Client, selector: string, scale: number) {
const clientRect = await getClientRect(client, selector)
const { Input } = client
export async function click(client: Client, selector: string, scale: number)
export async function click(client: Client, x: number, y: number)
export async function click(firstArg, secondArg, thirdArg, ...args: any[]) {

const options = {
x: Math.round((clientRect.left + clientRect.width / 2) * scale),
y: Math.round((clientRect.top + clientRect.height / 2) * scale),
const {Input} = firstArg

let options = {
button: 'left',
clickCount: 1,
x: 0,
y: 0
}

switch (typeof secondArg) {
case 'string': {
const clientRect = await getClientRect(firstArg, secondArg)
options.x = Math.round((clientRect.left + clientRect.width / 2) * thirdArg)
options.y = Math.round((clientRect.left + clientRect.height / 2) * thirdArg)
}
case 'number': {
options.x = secondArg;
options.y = thirdArg;
}
}

await Input.dispatchMouseEvent({
Expand All @@ -172,6 +186,7 @@ export async function click(client: Client, selector: string, scale: number) {
...options,
type: 'mouseReleased',
})

}

export async function focus(client: Client, selector: string): Promise<void> {
Expand Down