File Exchange

image thumbnail


version 1.0 (1.97 KB) by

Program to set focus to objects (edit etc) without clicking with the mouse on them.

11 Ratings



No License

Set focus to objects. When starting a Matlab GUI it is normally not possible to activate the cursor in an edit object. Before you can type, you'll have to click with the mouse in the edit field. With setfocus it is possible to activate the cursor with program code by passing the object handle to setfocus. setfocus simply simulate a mouseclick in the area of the object.

Comments and Ratings (13)

Andrea Libri


Song (view profile)

The function doesnt work any more for 2014b! The mex file mouseclick cannot be executed.

James Rao

Martin, I really like your solution to this problem. I was wondering if you have the source to mouseclick, to recompile it into a mex32 file since dll support is being phased out

Tom N

Martin provides a very nice workaround. Exactly what I needed. Thanks man!

Marc O Donnagain

is this the same as uicontrol(handle)? I tried using this function before trying uicontrol which did what I wanted.

Jo Bergs

@ Anthony:
it took some time but actually i found
out that this only works with an small pause
mousePress(16) + mouseRelease(16)
at my system(linux);
but then its fine and
platform-independant(i guess).
Thanks for the hint.

Anthony Beaucamp

You can replace the MouseClick DLL with the following 2 lines in Matlab:
    Input = java.awt.Robot;

Ralph Schleicher

The setfocus command does not handle all failure cases. There is no source code for the mouseclick command. It does not work on Unix. Ask me for an improved version solving all issues.


I have incorporated your mouseclick.dll file into my matlab program and find it extremely useful! thank you!

Stefan Bleeck

works :-)

Brett Shoelson

Very useful...thanks, Martin!

David Abraham

Great! Does the job, MATLAB should have a focus property settable in GUIDE!

Yaron Keren

Solved the problem. When will this be available in MATLAB itself?


Inserted a drawnow after deleting the callback to update the figure data

I noticed an error in my source file. (Typed a instead of h, line 29)

MATLAB Release
MATLAB 6.1 (R12.1)

Inspired: clickfocus, jMouseEmu: Mouse Emulator (v2.3)

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

» Watch video