Xetera / ghost-cursor

🖱️ Generate human-like mouse movements with puppeteer or on any 2D plane
MIT License
1.08k stars 118 forks source link

Add clickCount functionality -> Update spoof.ts #79

Closed spatterIight closed 7 months ago

spatterIight commented 1 year ago

This commit adds a clickCount parameter to the click() function, similar to puppeteer's

The use case for me is highlighting all the text in an input field before typing into it, such that typing overwrites any value already present

I do not believe the waitForClick parameter would function as expected when specified simultaneously with this new clickCount parameter, so I suspect some changes may be needed before merged.

One thought I had was simply using a for loop to perform up() and down() repeatedly, preserving the delay. However it doesn't seem to work, I am not sure why.

await page.mouse.down()
if (options?.waitForClick !== undefined) { await delay(options.waitForClick) }
if (options?.clickCount !== undefined) {
  for(var i = 0; i < options.clickCount-1; i++) {
    await page.mouse.down()
    if (options?.waitForClick !== undefined) { await delay(options.waitForClick) }
    await page.mouse.up()
  }
await page.mouse.up()

awesome project btw!