File Exchange

image thumbnail

inputEmu: Keyboard & Mouse Emulator (v1.0.1)

version (7.05 KB) by Kesh Ikuma
A Java-based function to control keyboard & mouse programmatically


Updated 20 Sep 2010

View License

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

Cite As

Kesh Ikuma (2020). inputEmu: Keyboard & Mouse Emulator (v1.0.1) (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (40)

Jeff Weiss

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:


Has anyone else come across this issue?


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


Where is the inputlog.m ?

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'};

Suho Kim


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!


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

Matt H

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




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


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

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.

Kesh Ikuma

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

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

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

@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.

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


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

Kesh Ikuma

@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


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 :)


nevermind I figured it out...bravo


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

Ray Lee

Is a combination of more than two keys supported?

How to emulate Ctrl+Alt+C?

Kesh Ikuma

@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.


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


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

Kesh Ikuma

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


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

@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.


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



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

pri dec

Kesh Ikuma

@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.

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,

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

@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


previous v1.0.1 upload incorrect

Fixed a bug in subfunction, convertToLowLevelActions()

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux