Skip to content

Instantly share code, notes, and snippets.

@kentkrantz
Last active May 6, 2020 03:13
Show Gist options
  • Select an option

  • Save kentkrantz/279c1abc6610c996ef5362c72db3c3c3 to your computer and use it in GitHub Desktop.

Select an option

Save kentkrantz/279c1abc6610c996ef5362c72db3c3c3 to your computer and use it in GitHub Desktop.
// import functions from the main module of AutoTouch
const { findColors, findColorsAsync } = at
// Prepare parameters
const params = {
colors: [ // Required parameter
{ color: 16661296, x: 0, y: 0 },
{ color: 1751033, x: -53, y: 67 },
],
count: 3, // optional, default is 0, 0 means no limitation
region: null, // optional, default is null, null means the whole screen
debug: true, // optional, default is false, true means turn on the debug mode which will produce an image showing the finding process
rightToLeft: false, // optiona, default is false, true means do the finding from right to left of the screen
bottomToTop: false // optiona, default is false, true means do the finding from bottom to top of the screen
}
// Call findColors on synchronous way which WILL block here till get the result
const [result, error] = findColors(params)
if (error) {
alert('Failed to find colors, error: %s', error)
} else {
alert('Got result findColors', result);
}
// You can also ignore the error checking like this
// const [result] = findColors(params)
// Call findColors on asynchronous way which WILL NOT block here
findColorsAsync(params, (result, error) => {
if (error) {
alert('Failed to find colors, error: %s', error)
return
}
alert('Got result findColorsAsync', result, error);
})
console.log('Arrive here before findColorsAsync returns result');
function callback(result, error) {
if (error) {
alert('Failed to find colors, error: %s', error)
return
}
alert('Got result findColorsAsync', result, error);
}
findColorsAsync(params, callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment