File Exchange

image thumbnail

inputEmu: Keyboard & Mouse Emulator (v1.0.1)

version 1.2 (7.05 KB) by

A Java-based function to control keyboard & mouse programmatically

15 Downloads

Updated

View License

INPUTEMU emulates user inputs via keyboard and mouse.

For example, executing the following line in the Matlab command window

inputemu({...
   'key_normal','Hello World\ENTER'
   'right_down',[];'right_up' []}') % <= notice the transpose!

yields in "Hello World" typed and executed in MATLAB command window (followed by an obvious error message) and right mouse click menu. For the detailed instructions, please run 'help inputemu'.

This function is a successor to my earlier submission JMOUSEEMU (linked below) with several notable changes:

* Added keyboard input support
* Changed input argument order
* Multiple-command CMDS input argument transposed (i.e., commands defined in columns not in rows)
* Removed support for Matlab HG specification

Also, as a future enhancement, I am planning to support non-US keyboards. The current version most likely produces incorrect characters for many non-alphabet characters with non-US keyboards. To improve this, please post here or contact me directly with feedback (as I only own QWERTY US keyboards)!

Comments and Ratings (39)

Daniel Natoli

This function been working perfectly until the latest macOS update (10.12.4). Currently, the function keys (F1 - F12) not do not parse with the following syntax:

inputemu('key_normal','\F10');

Has anyone else come across this issue?

Mengda Ren

Sam Williams@

for win8 and later version,Alt-Tab only works when you hand press the, but not works if you use vbs sendkeys or use this inputEmu.

However, an alternative is use Alt-Escape, which works for all of them!!!!!

Mengda Ren

Where is the inputlog.m ?

Sam Williams

Is there a way to change working tab (press ALT,TAB)? I've tried the method below

cmds =
{'key_down','\ALT'; 'key_normal','\TAB'; 'key_up','\ALT'};
inputemu(transpose(cmds))

Suho Kim

mbar170

Thank you for this excellent file. I've been using it for some time, but just discovered one extra feature that I needed to implement: the CMD key on mac computers.

From my testing, you just have to add the following line to the list of special keys:

'\COMMAND' KeyEvent.VK_META

I found this out from here: http://stackoverflow.com/questions/15418987/java-robot-keypress-command-key

Thanks again!

quickener

Have some problem. Lose window and put key to Matlab editor
cmds={'key_down','\CTRL';'key_down','\SHIFT';'key_normal','\ESC';'key_up','\CTRL';'key_up','\SHIFT';'key_normal','N\ENTER'}
I try to Launch Windows Task Manager and open window with "N" key in title

Matt H

Matt H (view profile)

Overall very useful submission. Thank you. I am able to get the multiple key presses working using the low level commands and inputing a 2 by N cell array for the command sequence. Here are some examples that might be helpful to other users:

% To Launch Windows Task Manager
cmds={'key_down','\CTRL';'key_down','\SHIFT';'key_normal','\ESC';'key_up','\CTRL';'key_up','\SHIFT'}
inputemu(transpose(cmds))

% To Take a Screenshot in Google Earth
cmds={'key_down','\CTRL';'key_down','\ALT';'key_normal','c';'key_up','\CTRL';'key_up','\ALT'}
inputemu(transpose(cmds))

Thanks

Werner

Werner (view profile)

Silvan

Silvan (view profile)

Uh, I found the source of problem. My keyboard setting was to "Slovenian" and not to US. Now it works fine.

Silvan

Silvan (view profile)

I have a problem with writting texts, which are path names (example C:\Test\FileName.txt). Namely, if text includes character / or \, function interrumpts with an error. My question is, does anybody knows a trick to avoid this problem. Thank you.

Kesh Ikuma

Kesh Ikuma (view profile)

Another possibility (the simplest):

inputemu('key_ctrl','Y');

On paper, this should do what you want to do, but donno for sure if it'll work. Please post your results.

Kesh Ikuma

Kesh Ikuma (view profile)

oops, insert a comma (,) between KEYBOARD_ACTION and key in each call

ravish kumar

sir, can u illustrate how to emulate ctrl+shift+y.
Comments above regarding this is not clear!!!!!!!

ravish kumar

thank you sir for the reply.INPUTEMU function is running fine in standalone c application devloped on my pc which have matab installed.
I will let u know if this standalone application fails on other pc without matlab!!!!!!!!!!

Kesh Ikuma

Kesh Ikuma (view profile)

@Ravish, I highly doubt that this function would work in the manner you are trying to use it. This function utilizes Java library within Matlab, which is likely inaccessible by a standalone C program as is. Although I'm not familiar with it, I suggest you to look into Java Native Interface.

ravish kumar

sir,i m trying to implement this function in a c prgrm.matlab compiler once compiled the fyl and it worked fine.bt now it is showing problem.Though it gets compiled,bt it doesnt do desired task ,ehen .exe file is executed..instead,it shows error!!!!!!!!!!!!!

Hanna

Hanna (view profile)

Wow, sorry, the problem was that my variable wasnt saved as characters.. me so stupid. Thanks for the help!

Kesh Ikuma

Kesh Ikuma (view profile)

@Hanna, your example works the way you have it. You might want to make sure that the cursor is placed on the window where you want to type the text to

Hanna

Hanna (view profile)

Hey! This might be an easy question, but does anyone know how to make the keyboard type the content of a variable you have set?
For instance:
variable= test 1
inputemuu(‘key_normal’,variable)

I would like this to type “test 1″
Any help would be appreciated :)

George

George (view profile)

nevermind I figured it out...bravo

George

George (view profile)

I get the following error while trying to use the program:

Attempt to execute SCRIPT varargin as a function:
C:\Program Files\MATLAB\R2011b\toolbox\matlab\lang\varargin.m

Error in inputemu (line 115)
[cmds,deltaT,idx_mouse,oemChars,msg] =
parseInput(defaultOemChars,nargin,varargin);

Sorry if I'm doing something wrong, I'm rather new to MatLab

Ray Lee

Is a combination of more than two keys supported?

How to emulate Ctrl+Alt+C?

Kesh Ikuma

Kesh Ikuma (view profile)

@Stan - Yes you can but you have to use the lower level commands: 'key_up' and 'key_down'.

'key_down' CTRL
'key_down' ALT
'key_normal' C
'key_up' ALT
'key_up' CTRL

would achieve your example.

Stanv13

hi, excellent program to a question, please is posible use 3 keys at once, according to your syntax is only possible 2. Example Ctrl + Alt + C. Is posible?? or changes must be made, thanks

Yuki

Yuki (view profile)

Thank you very much for your kind advice and great code.
I can use inputemu successfully.

Kesh Ikuma

Kesh Ikuma (view profile)

@Yuki - My bad, use '\F05' instead. It needs to be '\F##' with two digit number.

Yuki

Yuki (view profile)

Thank you for the prompt reply.
I use inputemu('key_normal','\F5'),
but I get a error of Invalid key @inputme at 120.

Is it depend on keyboard type?
My keyboard is japanese type.

Kesh Ikuma

Kesh Ikuma (view profile)

@Yuki - Yes, function keys are supported (I mistakenly left them out in the help text). Use '\F5' for F5 key press, and similar syntax for the others.

Yuki

Yuki (view profile)

I like this. Thanks.
Is it possible to use Function-key?
e.g. F5 for debug continue.

Yuki

Yuki (view profile)

lin

lin (view profile)

Excellent Programe, I can't not love it more. Thank you Soooo much

pri dec

Kesh Ikuma

Kesh Ikuma (view profile)

@Johannes - Yes, I have written the "recorder" but not up'ed here yet since it's a (32-bit) Windows specific MEX function (TMW does not accept binary file submission here).

For your disposal, you can download the MEX binary from

http://tinyurl.com/2cxvgwy (Links to my Google Doc)

Read help text for inputlog.m for details but what this function returns can be used as the command cell matrix for inputemu.m.

Use it at your own discretion. And, again, this program is intended for 32-bit Windows. I will eventually post the source here at FEX but probably not in immediate near future.

Johannes Korsawe

Really nice tool. I did not even think, that this could be working.

Is there any way to "record" your mouse&keyboard actions in order to replay them lateron with your program?

Best regards,
Johannes

Y Mehta

Thanks. I will download the new version. This is a fantastic program. I am using this to create self training files for my softwares.

Kesh Ikuma

Kesh Ikuma (view profile)

@Yogesh - Thx for the report. The bug has been fixed and updated version has been upped.

Y Mehta

I get an error with alternate and extend options.

inputemu('alternate',[1000 1000]);

??? Undefined variable "KeyEvent" or class "KeyEvent.VK_CONTROL".

Error in ==> inputemu>convertToLowLevelActions at 347
params{I} = KeyEvent.VK_CONTROL;

Error in ==> inputemu at 119
[actions,params,dt,msg] = convertToLowLevelActions(cmds,deltaT,idx_mouse,oemChars);

Y Mehta

Updates

1.2

previous v1.0.1 upload incorrect

1.1

Fixed a bug in subfunction, convertToLowLevelActions()

MATLAB Release
MATLAB 7.10 (R2010a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video