Tuesday, 15 April 2014

Chrome Extension to control mouse/keyword -



Chrome Extension to control mouse/keyword -

given cannot in javascript due security implications. there other type of google extension/development api allow me chrome?

yes, there pointer lock api command mouse, check code reference pointer lock api.

demonstration

go http://www.google.co.in/ , click on logo of google, them can customize code command mouse movements , actions.

manifest.json

add content script , set permissions page.

{ "name":"pointer lock", "description":"http://stackoverflow.com/questions/14896728/chrome-extension-to-control-mouse-keyword", "version":"1", "manifest_version":2, "content_scripts": [ { "matches": ["http://www.google.co.in/"], "js": ["myscript.js"] } ], "permissions":["<all_urls>"] } myscript.js

this code locks pointer movement.

//check whether browser supports locking or not var havepointerlock = 'webkitpointerlockelement' in document; //get random element in http://www.google.co.in/ page var element = document.getelementbyid("hplogo"); //bind event listener element.addeventlistener("click", function () { if (havepointerlock) { // inquire browser lock pointer element.requestpointerlock = element.webkitrequestpointerlock; element.requestpointerlock(); //register lock alter callback document.addeventlistener('webkitpointerlockchange', changecallback, false); //register callback errors document.addeventlistener('webkitpointerlockerror', errorcallback, false); } else { alert("your browser not back upwards pointer lock, please upgrade it"); } }); function movecallback(e) { //track mouse movements console.log("mouse moved ..."); console.log(e.webkitmovementx); console.log(e.webkitmovementy); } function changecallback() { //check element whether locked expected element or not if (document.webkitpointerlockelement == element) { // pointer locked // enable mousemove listener document.addeventlistener("mousemove", movecallback, false); } else { // pointer unlocked // disable mousemove listener document.removeeventlistener("mousemove", movecallback, false); } } function errorcallback(e) { //log errors console.log(e); } reference pointer lock api content scripts

google-chrome google-chrome-extension google-chrome-devtools

No comments:

Post a Comment