0

I have an existing MATLAB program which after a keystroke displays an image on the left or right of the screen. The user then indicates via arrow key if the image is on the left or right. The program actually does a lot of other things, but that's the gist. This is for a WinXP computer using MATLAB 2008A.

I would like to do a large number (thousands) of iterations for this program in an attempt to determine why some computers running this program have dying graphics cards. I've already made a number of improvements to simplify existing code and reduce computational time, but I need a to test and show the improvement. GPU-Z records all the hardware variables I'm interested in for now, so I need a keypress script capable of supplying input to the MATLAB program automatically. Ideally, this would be a stand alone macro capable of being run completely independently.

After reading this question, I attempted to modify the batch script as follows:

@if (@CodeSection == @Batch) @then


@echo off

rem Use %SendKeys% to send keys to the keyboard buffer
set SendKeys=CScript //nologo //E:JScript "%~F0"

rem Start the other program in the same Window
start "" /B cmd

%SendKeys% "echo off{ENTER}"

set /P "=Wait and send a command: " < NUL
ping -n 100 -w 1 127.0.0.1 > NUL
%SendKeys% "2"

set /P "=Wait and send a command: " < NUL
%SendKeys% "3"

ping -n 30 -w 1 127.0.0.1 > NUL
%SendKeys% "2"

set /P "=Wait and send a command: " < NUL
%SendKeys% "1"

goto :EOF

@end


// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

In testing, the batch code seems to appropriately enter keystrokes into the active window (cmd, text files, browsers, etc). However, if I attempt to run my MATLAB program simultaneously, the batch execution stalls until the MATLAB program ends. Obviously this is useless to me in the current form.

I'd appreciate any suggestions on where to go from here. Is batch scripting even a viable solution for this kind of automation? If not, any suggestions? I'd prefer to stay away from 3rd party programs as much as possible, but if it's the easiest solution I'll consider it.

Community
  • 1
  • 1
VerrKol
  • 3
  • 1
  • 2
  • Perhaps [this](http://stackoverflow.com/questions/27933270/programmatically-press-an-enter-key-after-starting-exe-file-in-matlab) will be helpful – Luis Mendo Jan 21 '15 at 23:56
  • Please post the _real_ modified code that your are using with MATLAB. It is not useful to post code that you are not using... – Aacini Jan 22 '15 at 02:23

0 Answers0