Thread Subject: Simulating key presses for scripts

Subject: Simulating key presses for scripts

From: Srikanth

Date: 26 Jan, 2009 06:33:01

Message: 1 of 4

Hi
I got a script file (call it S.m) that has a menu interface (multi-
level), and for each sequence of choices I need to save the resulting
figures. I would prefer to automate the process, preferably without
editing the script file. I wonder if there is a way to simulate key
strokes? For example, if I write an m-file (call it the Main file) to
call the script, and could specify that when the script stops for user
input, feed it 1. At the next level, feed it 2... Then I just need to
loop over the choices in my Main and repeatedly call S for each
sequence.

Any suggestions?
Thanks
Srikanth

Subject: Simulating key presses for scripts

From: Walter Roberson

Date: 26 Jan, 2009 06:43:16

Message: 2 of 4

Srikanth wrote:

> I got a script file (call it S.m) that has a menu interface (multi-
> level), and for each sequence of choices I need to save the resulting
> figures. I would prefer to automate the process, preferably without
> editing the script file. I wonder if there is a way to simulate key
> strokes?

Possibly the java 'robot' class, which can be called from Matlab.


--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: Simulating key presses for scripts

From: us

Date: 26 Jan, 2009 09:37:19

Message: 3 of 4

Srikanth
> I wonder if there is a way to simulate key strokes...

one of the solutions (as proposed on june 14, 2006)

% create a fig + pushbutton
     fh=figure;
     fp=get(fh,'position');
     ss=get(0,'screensize');
     uh=uicontrol;
     set(uh,'style','pushbutton');
     set(uh,'callback','disp(''hello ML'');');
     set(uh,'units','normalized');
     set(uh,'position',[0,0,1,1]);
     set(uh,'string','wait for autopress...');
     shg();
% initialize the java engine
     import java.awt.*;
     import java.awt.event.*;
% ...create a robot
     rob=Robot;
% ...and let her do the work for you
     mx=fp(1)+fix(fp(3)/2);
     my=ss(4)-fp(2)-fix(fp(4)/2);
     pause(1);
     rob.mouseMove(mx,my);
     pause(1);
     rob.mousePress(InputEvent.BUTTON1_MASK);
     rob.mouseRelease(InputEvent.BUTTON1_MASK);
     set(uh,'string','DONE...');

us

Subject: Simulating key presses for scripts

From: Toby

Date: 20 Nov, 2009 13:32:34

Message: 4 of 4

with the code from Srikanth keystrokes can actually be simulated. just add:
rob.keyPress(KeyEvent.VK_ENTER)
rob.keyRelease(KeyEvent.VK_ENTER)
whether this will work for Srikanth i don't know but i thought i'd post it here since i was searching for this code for quite a while.

go to:
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html
for more info

"us " <us@neurol.unizh.ch> wrote in message <glk08f$a5e$1@fred.mathworks.com>...
> Srikanth
> > I wonder if there is a way to simulate key strokes...
>
> one of the solutions (as proposed on june 14, 2006)
>
> *code
>
> us

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
java Toby Hijzen 20 Nov, 2009 08:34:08
simulate Toby Hijzen 20 Nov, 2009 08:34:08
keystroke Toby Hijzen 20 Nov, 2009 08:34:08
robot Toby Hijzen 17 Nov, 2009 08:55:49
robot us 26 Jan, 2009 04:40:22
java us 26 Jan, 2009 04:40:22
code us 26 Jan, 2009 04:40:22
rssFeed for this Thread

Contact us at files@mathworks.com