Focus follows mouse in 2015a

2 次查看(过去 30 天)
Temu Gautama
Temu Gautama 2015-9-4
评论: Temu Gautama 2019-11-12
I have recently updated to R2015a on a windows 7 machine. I use focus-follows-mouse (you can change this in the registry), but it my Matlab window is one of the few windows where a mouse-click is necessary to make it the active window to type in. Has anyone experienced the same behaviour and is this by design?
  4 个评论
Temu Gautama
Temu Gautama 2019-11-12
I have found a workaround which yields acceptable results. I get automatic focus, but the matlab command window is also auto-raised. In any case, here's what I did:
I call this function from my startup.m to create a callback for the command window
function focus()
mde = com.mathworks.mde.desk.MLDesktop.getInstance;
cw = mde.getClient( 'Command Window' );
xCmdWndView = cw.getComponent(0).getViewport.getComponent(0);
h_cw = handle( xCmdWndView, 'CallbackProperties' );
commName = 'matlabFocus.exe';
dir1 = 'c:\SomePlace\';
comm1 = fullfile( dir1, commName );
function callMe( varargin )
dosFast( ['"' comm1 '" &'] );
end
set( h_cw, 'MouseEnteredCallback', @callMe );
end
This matlabFocus.exe I created using a tool called AutoIt. The code looks for the matlab window, activates it and sends ctrl-0 to switch to the command window.
Local $hWnd = WinGetHandle( "[REGEXPTITLE:MATLAB [7R]*]" );
If @error Then
MsgBox( $MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle of Matlab" )
Exit
EndIf
; Set focus of the matlab window
WinActivate( $hWnd ) ; This works
Send( "^0" ) ; Switch to command window
It's a bit of a clumsy work-around, but, hey, it works.
hth,
Temu
Temu Gautama
Temu Gautama 2019-11-12
I forgot the function dosFast:
function dosFast( cmd1 )
hRuntime = java.lang.Runtime.getRuntime();
process = hRuntime.exec( cmd1 );
% status = process.waitFor();
end
(can be put in the focus() function before the callMe() definition)

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by