Skip to content

Instantly share code, notes, and snippets.

@kwoktung
Last active June 8, 2018 01:49
Show Gist options
  • Save kwoktung/be61e974ff947c3eb59346961e6e09a2 to your computer and use it in GitHub Desktop.
Save kwoktung/be61e974ff947c3eb59346961e6e09a2 to your computer and use it in GitHub Desktop.
;(function() {
var canvas = document.getElementsByClassName('runner-canvas')[0];
var ctx = canvas.getContext('2d');
function run(){
var hit = false;
var data = ctx.getImageData(150,180,175,50).data
for(var i=3, len = data.length; i < len; i += 8) {
if (data[i] > 0) {
hit = true;
break;
}
}
if(hit) {
var event = new KeyboardEvent('keydown', { key: 'ArrowUp', keyCode: 38, location: 0 });
document.dispatchEvent(event)
}
requestAnimationFrame(run)
}
run()
})()
@kwoktung
Copy link
Author

kwoktung commented Jun 8, 2018

不同版本浏览器像素提取范围不一样,部分浏览器可能需要 (100, 100, 50, 10),脚本只是提供一个基本的思路

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment