taohe 发表于 2004-1-22 22:32:33

【原创】新年礼物:在matlab捕捉F1等热键

今天是2004年,猴年正月初一,先祝大家新春快乐,万事如意。

趁着节日放假,得空写了这个函数。特此分享给SimWe里喜欢matlab的朋友们。这是首发,本人只在SimWe发布,如要转载,请注明出处。谢谢合作。

我们知道,在迄今为止的matlab发行版本中,我们无法捕捉F1等特殊功能健的动作。这也是在国际matlab讨论作里时常有人问但却没有解决的问题。我们当然可以等待Mathworks在matlab的下一个版本中解决这个问题。而我这里提供的这个函数,就是以mex形式,调用Windows API函数,来达到捕捉F1等热键的目的。当然这个解决办法只能用在Windows平台。

附件包含以下几个文件:
wgfcnkey.dll
wgfcnkey.m
testfcnkey.m
testfcnkey.fig
fcnkeyfunc.m
readme.txt

这里是中英文的readme.txt:

wgfcnkey.dll ---- A mex file, which captures pressing of fucntion keys
                  (F1, F2, ..., F12) in matlab applications on Windows
    platforms. For the usage, use this function in the
    implementation of the KeyPressFcn function. Based on
    the returned value, you'll know whether a function
    key was pressed.

wgfcnkey.m ---- Help file for wgfcnkey.dll

testfcnkey.m
testfcnkey.fig
fcnkeyfunc.m ---- A simple matlab gui application to test wgfcnkey.dll.
                  To start, run testfcnkey in matlab, and press a function
    or any other key.

=========================================================================
wgfcnkey.dll ---- 一个matlab mex 文件,可以用来在matlab程序中捕捉用户按下
                  的特殊功能健:F1, F2, ..., F12. 使用时,在你的应用程序的
    KeyPressFcn的函数体里,是用wgfcnkey,根据其返回值,判断
    是否有功能健被按下。

wgfcnkey.m ---- wgfcnkey.dll的帮助文件。

testfcnkey.m
testfcnkey.fig
fcnkeyfunc.m ---- 一个简单的matlab图形界面程序,用来测试wgfcnkey.dll。运行
                  方法:在matlab里执行testfcnkey.m,然后按下某个功能健或者
    其他的任意健。
                   


欢迎大家测试。

simwe 发表于 2004-1-23 00:24:22

回复: 【原创】新年礼物:在matlab捕捉F1等热键

祝大家新年快乐,谢谢taohe 的分享!

bigrice 发表于 2004-1-23 20:14:40

回复: 【原创】新年礼物:在matlab捕捉F1等热键

支持Taohe兄的精品!

祝新年快乐!

cwit 发表于 2004-1-29 17:45:33

回复: 【原创】新年礼物:在matlab捕捉F1等热键

通过多次测试,发现两个很简单的方法获取F1键等功能键。
方法1:在“KeyPressFcn“里面提取figure的”CurrentKey“属性,可以得到”f1“~“f12”等功能键,以及一般的数字键和字母键。
方法2:编辑fiugre的“HelpFcn”属性,按下F1键时将自动调用这个属性指向的函数。
同时谢谢taohe兄的帮助!

taohe 发表于 2004-1-29 20:16:57

回复: 【原创】新年礼物:在matlab捕捉F1等热键

哦,我倒是忘了这个CurrentKey,只是一个没有在文档中说明的特性。好像是从6.0以后的版本都有这个,但是即使在最新版6.5.1得文档里,好像也没有提到figure窗口的这个属性。

至少在Windows平台,利用figure窗口的CurrentKey属性,可以检测标准键盘的所有键。

刚才试了一下,发现了一个缺憾:CurrentKey无法区分左、右Shift, Ctrl, 和Alt. 我也想不出去份这几个键有什么应用,不过如果能区分的话,应该不是件坏事,另外,也为了使我自己的函数多点功能,于是我改了一下程序,加入了区分这六个键的功能。新的函数的用法没有变,仍然是在GUI应用的KeyPressFcn里调用wgfcnkey函数,然后根据函数返回值,判断是哪个键被按下。对应于这六个键的函数值分别是:

13 ---- left Shift
14 ---- left Ctrl
15 ---- left Alt
16 ---- right Shift
17 ---- right Ctrl
18 ---- right Alt


更新过的文件在这个附件中。Have fun! :I

cwit 发表于 2004-1-30 09:58:05

回复: 【原创】新年礼物:在matlab捕捉F1等热键

请问组合键能够识别吗?
谢谢!

bigrice 发表于 2004-1-30 19:00:25

回复: 【原创】新年礼物:在matlab捕捉F1等热键

Jack Little:”同志们,我代表Mathworks公司向你们致以崇高的敬意,你们用我们开发的软件做出了我们做不到的事情。”

哈哈,谢谢楼上几位大牛,大家继续讨论!

秋之剑 发表于 2004-3-17 13:42:04

回复: 【原创】新年礼物:在matlab捕捉F1等热键

害羞的问一句,那些热键都有什么功用啊?
我现在才刚开始学MATLAB,对它还一点都不知道唉。
谢谢各位了。

cwit 发表于 2004-3-17 19:52:11

回复: 【原创】新年礼物:在matlab捕捉F1等热键

就是打开帮助文件,比如用键盘打开***.chm文件。因为有事鼠标不好用,你要保证键盘可以用。

snow_man_0 发表于 2004-8-12 16:48:01

回复: 【原创】新年礼物:在matlab捕捉F1等热键

"请问组合键能够识别吗? "
"谢谢!"
   
   
   
可以做一个隐藏菜单把要用的组合键都定义在里面

bainhome 发表于 2005-8-7 15:45:03

Re:回复: 【原创】新年礼物:在matlab捕捉F1等热键

bigrice wrote:
Jack Little:”同志们,我代表Mathworks公司向你们致以崇高的敬意,你们用我们开发的软件做出了我们做不到的事情。”

哈哈,谢谢楼上几位大牛,大家继续讨论!

又删掉了几个垃圾贴,再顶出来,看到前辈所作的工作,有一种羞愧得想死掉的感觉.很羡慕大米,你当版主时逢几大高手创作力最旺盛的时期,每天一定都会迫不及待地打开simwe的网页...
真是令人向往...:)
(同时,也希望除非有一定的见解,否则别发"好","顶","佩服"之类的垃圾贴,对这些我不会手软...:D)

03120416 发表于 2010-12-27 22:27:29

虽然有些古老了,但是确实现在需要用

ChaChing 发表于 2011-10-30 21:33:21

本帖最后由 ChaChing 于 2011-10-30 21:36 编辑

虽然印象中好像看过这些属性, 但刚刚怎都没help到figure的"CurrentKey"及"HelpFcn"属性 ?? 跟版本有关吗?
CurrentKey是否应该是CurrentCharacter ??

真是一个没有在文档中说明的特性吗? 试过get(gcf,'CurrentKey'), 真有! 想学下, 怎知道有这些属性!?

BTW: 被我盗用转贴/分享了

nwcwww 发表于 2011-10-31 01:20:48

ChaChing 发表于 2011-10-30 21:33 static/image/common/back.gif
虽然印象中好像看过这些属性, 但刚刚怎都没help到figure的"CurrentKey"及"HelpFcn"属性 ?? 跟版本有关吗?
C ...

比较一下:

>>z=peaks(50);imagesc(z);get(gcf)


        Alphamap = [ (1 by 64) double array]
        CloseRequestFcn = closereq
        Color =
        Colormap = [ (64 by 3) double array]
        CurrentAxes =
        CurrentCharacter =
        CurrentObject = []
        CurrentPoint =
        DockControls = on
        FileName =
        IntegerHandle = on
        InvertHardcopy = on
        KeyPressFcn =
        KeyReleaseFcn =
        MenuBar = figure
        Name =
        NextPlot = add
        NumberTitle = on
        PaperUnits = centimeters
        PaperOrientation = portrait
        PaperPosition =
        PaperPositionMode = manual
        PaperSize =
        PaperType = A4
        Pointer = arrow
        PointerShapeCData = [ (16 by 16) double array]
        PointerShapeHotSpot =
        Position =
        Renderer = painters
        RendererMode = auto
        Resize = on
        ResizeFcn =
        SelectionType = normal
        ToolBar = auto
        Units = pixels
        WindowButtonDownFcn =
        WindowButtonMotionFcn =
        WindowButtonUpFcn =
        WindowKeyPressFcn =
        WindowKeyReleaseFcn =
        WindowScrollWheelFcn =
        WindowStyle = normal
        WVisual = 00 (RGB 32GDI, Bitmap, Window)
        WVisualMode = auto

        BeingDeleted = off
        ButtonDownFcn =
        Children =
        Clipping = on
        CreateFcn =
        DeleteFcn =
        BusyAction = queue
        HandleVisibility = on
        HitTest = on
        Interruptible = on
        Parent =
        Selected = off
        SelectionHighlight = on
        Tag =
        Type = figure
        UIContextMenu = []
        UserData = []
        Visible = on

添加一句命令,会发现多了不少属性:

>>z=peaks(50);imagesc(z);set(0,'hideundocumented','off');get(gcf)



        Alphamap = [ (1 by 64) double array]
        BackingStore = on
        CloseRequestFcn = closereq
        Color =
        Colormap = [ (64 by 3) double array]
        CurrentAxes =
        CurrentCharacter =
        CurrentKey = alt
        CurrentModifier = [ (1 by 0) cell array]
        CurrentObject = []
        CurrentPoint =
        DithermapWarning: figure Dithermap is no longer useful with TrueColor displays,
and will be removed in a future release.
= [ (64 by 3) double array]
        DithermapModeWarning: figure DithermapMode is no longer useful with TrueColor displays,
and will be removed in a future release.
= manual
        DockControls = on
        DoubleBuffer = on
        FileName =
        FixedColorsWarning: figure FixedColors produces a warning and will be removed in a future release
= [ (10 by 3) double array]
        HelpFcn =
        HelpTopicMap =
        IntegerHandle = on
        InvertHardcopy = on
        KeyPressFcn =
        KeyReleaseFcn =
        MenuBar = figure
        MinColormapWarning: figure MinColormap produces a warning and will be removed in a future release
=
        Name =
        JavaFrameWarning: figure JavaFrame property will be obsoleted in a future release. For more
information see the JavaFrame resource on the MathWorks web site.
= [ (1 by 1) com.mathworks.hg.peer.FigurePeer array]
        NextPlot = add
        NumberTitle = on
        PaperUnits = centimeters
        PaperOrientation = portrait
        PaperPosition =
        PaperPositionMode = manual
        PaperSize =
        PaperType = A4
        Pointer = arrow
        PointerShapeCData = [ (16 by 16) double array]
        PointerShapeHotSpot =
        Position =
        OuterPosition =
        ActivePositionProperty = position
        PrintTemplate = []
        ExportTemplate = []
        Renderer = painters
        RendererMode = auto
        Resize = on
        ResizeFcn =
        SelectionType = normal
        ToolBar = auto
        Units = pixels
        WaitStatus = []
        WindowButtonDownFcn =
        WindowButtonMotionFcn =
        WindowButtonUpFcn =
        WindowKeyPressFcn =
        WindowKeyReleaseFcn =
        WindowScrollWheelFcn =
        WindowStyle = normal
        WVisual = 00 (RGB 32GDI, Bitmap, Window)
        WVisualMode = auto
        UseHG2 = off

        BeingDeleted = off
        PixelBounds =
        ButtonDownFcn =
        Children =
        Clipping = on
        CreateFcn =
        DeleteFcn =
        BusyAction = queue
        HandleVisibility = on
        HelpTopicKey =
        HitTest = on
        Interruptible = on
        Parent =
        Selected = off
        SelectionHighlight = on
        Serializable = on
        Tag =
        Type = figure
        UIContextMenu = []
        UserData = []
        ApplicationData = [ (1 by 1) struct array]
        Behavior = [ (1 by 1) struct array]
        Visible = on
        XLimInclude = on
        YLimInclude = on
        ZLimInclude = on
        CLimInclude = on
        ALimInclude = on
        IncludeRenderer = on

这些undocumented的属性可以用下面的方法查看:
>>List=get(classhandle(handle(gcf)),'Properties');
>>IfVisible=get(List,'Visible');
>>Hidden=List(strcmp(IfVisible,'off'));
>>get(Hidden,'Name')

ans =

    'BackingStore'
    'CurrentKey'
    'CurrentModifier'
    'Dithermap'
    'DithermapMode'
    'DoubleBuffer'
    'FixedColors'
    'HelpFcn'
    'HelpTopicMap'
    'MinColormap'
    'JavaFrame'
    'OuterPosition'
    'ActivePositionProperty'
    'PrintTemplate'
    'ExportTemplate'
    'WaitStatus'
    'UseHG2'
    'PixelBounds'
    'HelpTopicKey'
    'Serializable'
    'ApplicationData'
    'Behavior'
    'XLimInclude'
    'YLimInclude'
    'ZLimInclude'
    'CLimInclude'
    'ALimInclude'
    'IncludeRenderer'



cwit 发表于 2011-11-6 19:48:28

楼上的比较细心。这些隐藏的属性还是很有用的,值得大家细细研究。
页: [1]
查看完整版本: 【原创】新年礼物:在matlab捕捉F1等热键