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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!