Monday, May 14, 2012

MATLAB Implementation One

As mentioned in Week 6's post, a website was found containing code  that could be run through MATLAB that would programmatically control the mouse movements on a computer screen.  Currently,  MATLAB does not its own code that can access cursor movement, whereas a Java class, more specifically "java.awt.Robot," can.  This Java class executes cursor functions which can be manipulated via MATLAB code.  One of the Java Class functions found was a mouse clicking script.  Figure 1 shows an example code for a particular mouse clicking function.



import java.awt.Robot;
import java.awt.event.*;
mouse = Robot;

mouse.mousePress(InputEvent.BUTTON3_MASK);
mouse.mouseRelease(InputEvent.BUTTON3_MASK);
 
 








Figure 1: Java class code used to programmatically click the mouse on a computer screen.

Also, another code was found that demonstrated how to move a cursor on a computer screen.  When this code was run, the cursor would begin in the upper left hand corner of the computer screen and move down diagonally because it follows the screen resolution defined by MATLAB.



import java.awt.Robot;
mouse = Robot;

mouse.mouseMove(0, 0);
screenSize = get(0, 'screensize');
for i = 1: screenSize(4)
mouse.mouseMove(i, i);
pause(0.00001);
end
 
 














Figure 2: Java class code used to programmatically move the cursor on a computer screen.

            Using these Java class codes, the goal is to be able to use the electrodes to control the mouse movements instead of manually picking points in which the cursor would be moved to.  The plan is to create a function that takes the inputs of initial position, direction of movement, and extent of motion to determine a new position of the cursor.  Then, the new position would be looped into the initial position of the function to create a new final position.  As for the mouse clicking, a function was created that takes the input of type, amount, and delay to determine whether the mouse was clicked and released or was not.  The type differentiates between left and right clicking of the mouse, which is expressed in a switch that executes code that follows the switch.  The amount determines how often the mouse would be clicked and released, expressed by a for loop surrounding the pressing and releasing action.  The delay is the amount of time of delay between clicking and releasing the mouse.

No comments:

Post a Comment