View License

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

» Watch video

Highlights from
inputEmu: Keyboard & Mouse Emulator (v1.0.1)

5.0 | 11 ratings Rate this file 24 Downloads (last 30 days) File Size: 7.05 KB File ID: #28603 Version: 1.2

inputEmu: Keyboard & Mouse Emulator (v1.0.1)


Kesh Ikuma (view profile)


31 Aug 2010 (Updated )

A Java-based function to control keyboard & mouse programmatically

| Watch this File

File Information

INPUTEMU emulates user inputs via keyboard and mouse.

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

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


J Mouse Emu: Mouse Emulator (V2.3) inspired this file.

This file inspired Heightprofile From Google Earth To 3 D Surface and J Mouse Emu: Mouse Emulator (V2.3).

MATLAB release MATLAB 7.10 (R2010a)
Other requirements Java.awt support
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (36)
23 Feb 2016 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'};

Comment only
18 Feb 2016 Suho Kim

23 Jul 2015 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:


I found this out from here:

Thanks again!

17 Jun 2015 quickener

Have some problem. Lose window and put key to Matlab editor
I try to Launch Windows Task Manager and open window with "N" key in title

Comment only
26 Mar 2014 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

% To Take a Screenshot in Google Earth


01 Oct 2013 Werner

Werner (view profile)

15 Sep 2012 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.

Comment only
15 Sep 2012 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.

Comment only
30 Apr 2012 Kesh Ikuma

Kesh Ikuma (view profile)

Another possibility (the simplest):


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

Comment only
30 Apr 2012 Kesh Ikuma

Kesh Ikuma (view profile)

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

Comment only
30 Apr 2012 ravish kumar

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

Comment only
29 Apr 2012 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!!!!!!!!!!

Comment only
24 Apr 2012 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.

Comment only
24 Apr 2012 ravish kumar

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

Comment only
29 Mar 2012 Hanna

Hanna (view profile)

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

Comment only
29 Mar 2012 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

Comment only
29 Mar 2012 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

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

Comment only
20 Jan 2012 George

George (view profile)

nevermind I figured it out...bravo

20 Jan 2012 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] =

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

Comment only
07 Sep 2011 Ray Lee

Is a combination of more than two keys supported?

How to emulate Ctrl+Alt+C?

Comment only
06 Sep 2011 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.

Comment only
06 Sep 2011 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

28 Mar 2011 Yuki

Yuki (view profile)

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

Comment only
27 Mar 2011 Kesh Ikuma

Kesh Ikuma (view profile)

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

Comment only
27 Mar 2011 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.

Comment only
25 Mar 2011 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.

Comment only
25 Mar 2011 Yuki

Yuki (view profile)

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

Comment only
25 Mar 2011 Yuki

Yuki (view profile)

16 Dec 2010 lin

lin (view profile)

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

22 Nov 2010 pri dec

23 Sep 2010 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 (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.

Comment only
23 Sep 2010 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,

20 Sep 2010 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.

Comment only
20 Sep 2010 Kesh Ikuma

Kesh Ikuma (view profile)

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

Comment only
20 Sep 2010 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);

Comment only
17 Sep 2010 Y Mehta

20 Sep 2010 1.1

Fixed a bug in subfunction, convertToLowLevelActions()

20 Sep 2010 1.2

previous v1.0.1 upload incorrect

Contact us