How to check if matlab window has focus

조회 수: 9 (최근 30일)
Pawel Blaszczyk
Pawel Blaszczyk 2014년 1월 27일
편집: per isakson 2014년 1월 28일
Hello, My target is to create a time-object which will check every 10 minutes if Matlab is used. Do you have any ideas how to do it? I know how to create time object and how to use startup.m, finish.m scripts, but how can I verify if Matlab is running (and really in use) or it is just minimalized or covered by another window when user does something else?
Best regards, Pawel
  댓글 수: 4
Walter Roberson
Walter Roberson 2014년 1월 27일
Which operating system?
Pawel Blaszczyk
Pawel Blaszczyk 2014년 1월 28일
Window$ 7

댓글을 달려면 로그인하십시오.

채택된 답변

per isakson
per isakson 2014년 1월 27일
편집: per isakson 2014년 1월 28일
I guess you use Windows
  • download PsList (better than tasklist)
  • the timer callback function shall call pslist.exe
% pslist.exe shall be in the same folder as this function
dos_fmt = [ fullfile( fileparts( which( mfilename ) ), 'pslist.exe' ), ' %s' ];
dos_fmt = strrep( dos_fmt, '\', '\\' );
dos_cmd = sprintf( dos_fmt, num2str(val) ); % num2str takes strings
mlb_cmd = sprintf( 'dos( ''%s'' );', dos_cmd );
dos_buf = evalc( mlb_cmd );
where val is equal to 'matlab' (or it's ProcessID)
Compare the current CPU Time and Elapsed Time with the previous ones.
An alternative is JavaScript in combination with the windows script host, wscript
  댓글 수: 6
Walter Roberson
Walter Roberson 2014년 1월 28일
Sorry I do not seem to be able to find the discussion that I recently saw. I seldom use MS Windows so I do not know the particular jargon that would have to be used for the query.
Sort of relevant to the overall task:
per isakson
per isakson 2014년 1월 28일
편집: per isakson 2014년 1월 28일
Pawel, this question at Stackoverflow might help you get started How can I tell if a Window has focus? (Win32 API). See also the Linked and Related questions.
I use the approach I proposed to determine if a process has finished working; isn't using more cpu-cycles.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by