Has anyone else encountered a bug in get(gcf, 'CurrentModifier') or WindowKeyPressFcn in general?

조회 수: 5 (최근 30일)
When executing a basic WindowKeyPressFcn callback in a GUI to determine the current key and modifier, I've encountered some unexpected behavior. It may be related to my running Windows7 in full screen mode on a mac through Parallels, with Matlab running on Windows. But maybe someone else has seen the same issues.
The code that I am calling is the following:
CurrentKey = get(GLOBALFORMHANDLE, 'CurrentKey');
CurrentModifier = get(GLOBALFORMHANDLE, 'CurrentModifier');
1. Sometimes the event registers two key presses having occurred when the screen space was recently changed from my mac back to my pc. 2. When alt is held down, it is recorded as {'control'}. This is true regardless of whether I've changed from Mac to PC or not which makes me think that it's a general issue. 3. When both control and alt are held down, it only records {'control'} for the first key press. It records {'control' 'alt'} for the second and subsequent key presses. Repolling the value of CurrentKey and CurrentModifier do not change the behavior.
I have some workarounds for these. For example, I've created a persistent variable which is set to now and I test to make sure that the function hasn't executed in the past 0.1 seconds (roughly the fastest time to press two keys that is physiologically possible). And I use 'control' and 'shift' as my modifiers even though I had wanted to use 'control' and 'alt'.
Here's the 0.1 second lockout code:
persistent lastCallTime
if ~isempty(lastCallTime);
if now-lastCallTime < (1/(24*60*60*10)); %If they clicked on this in the last 0.1 seconds.
lastCallTime = now;
return;
else
lastCallTime = now;
end
else
lastCallTime = now;
end
But has anyone else noticed a similar issue? I can work with the MathWorks to trap the error if it's hard to reproduce.
-Davio

답변 (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