12

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!!!!



|

12 Comments


I have read your blog its very attractive and impressive. I like it your blog.

Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai


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


Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
rpa training in bangalore
best rpa training in bangalore
rpa training in pune | rpa course in bangalore
rpa training in chennai


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


Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

AWS Training in Bangalore | Best AWS Amazon Web Services…
Amazon Web Services (AWS) Training in Pune India
AWS Training | AWS Training and Certification | AWS online training
AWS Training in Bangalore cost| Aws training in Bangalore with placements


All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
microsoft azure training in bangalore
rpa training in bangalore
best rpa training in bangalore
rpa online training


A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.
AWS training in chennai

AWS Training in Bangalore

Post a Comment

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