Chrome extension for mouse / keyword management

Given that you cannot do this in JavaScript due to security implications. Is there any other type of Google extension / development API that will allow me to do this from Chrome?

+7
source share
1 answer

Yes, there is an API with a pointer to control the mouse. This code can be used as a reference for a pointer API.

Demonstration

Go to http://www.google.co.in/ and click on the Google Logo, from which you can configure this code to control mouse movements and actions.

manifest.json

Add the contents of the script and put all the permissions for the 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 blocks the movement of the pointer.

 //Check whether browser supports locking or not var havePointerLock = 'webkitPointerLockElement' in document; //Get some random element in http://www.google.co.in/ page var element = document.getElementById("hplogo"); //Bind an event Listener element.addEventListener("click", function () { if (havePointerLock) { // Ask the browser to lock the pointer element.requestPointerLock = element.webkitRequestPointerLock; element.requestPointerLock(); //Register lock change callback document.addEventListener('webkitpointerlockchange', changeCallback, false); //Register callback for all errors document.addEventListener('webkitpointerlockerror', errorCallback, false); } else { alert("Your browser does not support Pointer Lock, Please Upgrade it"); } }); function moveCallback(e) { //Track all mouse movements console.log("Mouse Moved ..."); console.log(e.webkitMovementX); console.log(e.webkitMovementY); } function changeCallback() { //Check for element whether locked is expected element or not if (document.webkitPointerLockElement == element) { // Pointer was just locked // Enable the mousemove listener document.addEventListener("mousemove", moveCallback, false); } else { // Pointer was just unlocked // Disable the mousemove listener document.removeEventListener("mousemove", moveCallback, false); } } function errorCallback(e) { //Log Errors console.log(e); } 

Link

+4
source

All Articles