Code covered by the BSD License  

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

5.0

5.0 | 9 ratings Rate this file 35 Downloads (last 30 days) File Size: 7.05 KB File ID: #28603

inputEmu: Keyboard & Mouse Emulator (v1.0.1)

by

 

31 Aug 2010 (Updated )

A Java-based function to control keyboard & mouse programmatically

| Watch this File

File Information
Description

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

Acknowledgements

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 (32)
26 Mar 2014 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
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

01 Oct 2013 Werner  
15 Sep 2012 Silvan

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

15 Sep 2012 Silvan

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.

30 Apr 2012 Kesh Ikuma

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.

30 Apr 2012 Kesh Ikuma

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

30 Apr 2012 ravish kumar

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

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

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

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

29 Mar 2012 Hanna

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

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

29 Mar 2012 Hanna

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

20 Jan 2012 George

nevermind I figured it out...bravo

20 Jan 2012 George

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

07 Sep 2011 Ray Lee

Is a combination of more than two keys supported?

How to emulate Ctrl+Alt+C?

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

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

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

27 Mar 2011 Kesh Ikuma

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

27 Mar 2011 Yuki

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.

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

25 Mar 2011 Yuki

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

25 Mar 2011 Yuki  
16 Dec 2010 lin

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

22 Nov 2010 pri dec  
23 Sep 2010 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

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.

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,
Johannes

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.

20 Sep 2010 Kesh Ikuma

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

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

17 Sep 2010 Y Mehta  
Updates
20 Sep 2010

Fixed a bug in subfunction, convertToLowLevelActions()

20 Sep 2010

previous v1.0.1 upload incorrect

Contact us