19

Mouse and Keyboard control in Matlab

Posted by SUYOG PATIL on 5:01 PM in , , ,
Mouse and keyboard control in Matlab:

After red object detection,if you want to do  mouse controls by red object then just follow steps as given below:

1)Get red objects centroid from current frame(Code shared already,see archive).

2)To set mouse cursor use java robot class or you can use inbuilt function in Matlab.
resource:
http://docs.oracle.com/javase/1.5.0/docs/api/java/awt/Robot.html

The following MATLAB code example demonstrates how one can programmatically control mouse motion using the java.awt.Robot class to move the mouse diagonally across the screen. First, import the class into MATLAB, create an object of this type, and then execute the mouseMove method in a loop to simulate motion.

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.01);
end


 

The following example demonstrates how one can programmatically click the right mouse button to bring up the context menu. Again, import the required Java classes, create an object of this type, and then use the mousePress and mouseRelease functions to simulate a click. Before executing this code, place the mouse over a portion of the screen where a context menu can appear.

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

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


resoure-http://www.mathworks.in/support/solutions/en/data/1-2X10AT/index.html?solution=1-2X10AT

3)you can set keyboard events by this robot class.Using this events 
a)You can control any application
b)Play any flash game


 voidkeyPress(int keycode)
          Presses a given key.
 voidkeyRelease(int keycode)
          Releases a given key.


Short summary of Robot class(one of my favorite) functions:
 void delay(int ms)
          Sleeps for the specified time.
 int getAutoDelay()
          Returns the number of milliseconds this Robot sleeps after generating an event.
 Color getPixelColor(int x, int y)
          Returns the color of a pixel at the given screen coordinates.
 boolean isAutoWaitForIdle()
          Returns whether this Robot automatically invokes waitForIdle after generating an event.
 void keyPress(int keycode)
          Presses a given key.
 void keyRelease(int keycode)
          Releases a given key.
 void mouseMove(int x, int y)
          Moves mouse pointer to given screen coordinates.
 void mousePress(int buttons)
          Presses one or more mouse buttons.
 void mouseRelease(int buttons)
          Releases one or more mouse buttons.
 void mouseWheel(int wheelAmt)
          Rotates the scroll wheel on wheel-equipped mice.
 void setAutoDelay(int ms)
          Sets the number of milliseconds this Robot sleeps after generating an event.
 void setAutoWaitForIdle(boolean isOn)
          Sets whether this Robot automatically invokes waitForIdle after generating an event.
 String toString()
          Returns a string representation of this Robot.
 void waitForIdle()
          Waits until all events currently on the event queue have been processed.




You can always see my work in this video in which I played counterstrike with hand gestures at end of video!!!!



|

19 Comments


The following MATLAB code example demonstrated how one can programmatically control mouse motion using the java.awt.Robot class to move the mouse diagonally across the screen.
Java Certification Training in Chennai


It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...

python training in rajajinagar
Python training in bangalore
Python training in usa


Have you been thinking about the power sources and the tiles whom use blocks I wanted to thank you for this great read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out the new stuff you post
Data Science training in Chennai
Data science training in Bangalore
Data science training in pune
Data science online training
Data Science Interview questions and answers
Data Science Tutorial


Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
Best Devops Training in pune
Devops Training in Bangalore

Microsoft azure training in Bangalore
Power bi training in Chennai


Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 
python Course in Pune
python Course institute in Chennai
python Training institute in Bangalore


This comment has been removed by the author.

Innovative thinking of you in this blog makes me very useful to learn.i need more info to learn so kindly update it.I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.

Data Science Training In Chennai

Data Science Online Training In Chennai

Data Science Training In Bangalore

Data Science Training In Hyderabad

Data Science Training In Coimbatore

Data Science Training

Data Science Online Training


Very useful and information content has been shared out here, Thanks for sharing it. oracle training in chennai


This comment has been removed by the author.

Attend The Data Scientist Courses From ExcelR. Practical Data Scientist Courses Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Scientist Courses. Data Scientist Courses


This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the good work. I have been meaning to write something like this on my website and you have given me an idea.
data scientist course


You completed certain reliable points there. I did a search on the subject and found nearly all persons will agree with your blog.
data scientist training in hyderabad


Brilliant Blog! I might want to thank you for the endeavors you have made recorded as a hard copy of this post. I am trusting a similar best work from you later on also. I needed to thank you for these sites! Much obliged for sharing. Incredible sites!
data science training in hyderabad


Thanks for the informative and helpful post, obviously in your blog everything is good..
full stack developer course

Post a Comment

Copyright © 2009 ALL ABOUT ROBOTICS!! All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.