找回密码
 注册
Simdroid-非首页
查看: 1073|回复: 14

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

[复制链接]
发表于 2004-1-22 22:32:33 | 显示全部楼层 |阅读模式 来自 新加坡
今天是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:
  1. wgfcnkey.dll ---- A mex file, which captures pressing of fucntion keys  
  2.                   (F1, F2, ..., F12) in matlab applications on Windows  
  3.       platforms. For the usage, use this function in the  
  4.       implementation of the KeyPressFcn function. Based on  
  5.       the returned value, you'll know whether a function  
  6.       key was pressed.  
  7.   
  8. wgfcnkey.m ---- Help file for wgfcnkey.dll
  9.   
  10. testfcnkey.m
  11. testfcnkey.fig  
  12. fcnkeyfunc.m ---- A simple matlab gui application to test wgfcnkey.dll.  
  13.                   To start, run testfcnkey in matlab, and press a function  
  14.       or any other key.
  15.   
  16. =========================================================================
  17. wgfcnkey.dll ---- 一个matlab mex 文件,可以用来在matlab程序中捕捉用户按下
  18.                   的特殊功能健:F1, F2, ..., F12. 使用时,在你的应用程序的
  19.       KeyPressFcn的函数体里,是用wgfcnkey,根据其返回值,判断
  20.       是否有功能健被按下。
  21.   
  22. wgfcnkey.m ---- wgfcnkey.dll的帮助文件。
  23.   
  24. testfcnkey.m
  25. testfcnkey.fig
  26. fcnkeyfunc.m ---- 一个简单的matlab图形界面程序,用来测试wgfcnkey.dll。运行
  27.                   方法:在matlab里执行testfcnkey.m,然后按下某个功能健或者
  28.       其他的任意健。
  29.                    
复制代码

  
欢迎大家测试。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×

评分

1

查看全部评分

发表于 2004-1-23 00:24:22 | 显示全部楼层 来自 广西玉林

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

Simdroid开发平台
祝大家新年快乐,谢谢taohe 的分享!
发表于 2004-1-23 20:14:40 | 显示全部楼层 来自 上海

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

支持Taohe兄的精品!
  
祝新年快乐!
发表于 2004-1-29 17:45:33 | 显示全部楼层 来自 上海闸北区

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

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

评分

1

查看全部评分

 楼主| 发表于 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函数,然后根据函数返回值,判断是哪个键被按下。对应于这六个键的函数值分别是:
  1. 13 ---- left Shift
  2. 14 ---- left Ctrl
  3. 15 ---- left Alt
  4. 16 ---- right Shift
  5. 17 ---- right Ctrl
  6. 18 ---- right Alt
复制代码

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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×

评分

1

查看全部评分

发表于 2004-1-30 09:58:05 | 显示全部楼层 来自 上海闸北区

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

请问组合键能够识别吗?
谢谢!
发表于 2004-1-30 19:00:25 | 显示全部楼层 来自 上海

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

Jack Little:”同志们,我代表Mathworks公司向你们致以崇高的敬意,你们用我们开发的软件做出了我们做不到的事情。”
  
哈哈,谢谢楼上几位大牛,大家继续讨论!
发表于 2004-3-17 13:42:04 | 显示全部楼层 来自 湖北十堰

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

害羞的问一句,那些热键都有什么功用啊?
我现在才刚开始学MATLAB,对它还一点都不知道唉。
谢谢各位了。
发表于 2004-3-17 19:52:11 | 显示全部楼层 来自 上海浦东新区

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

就是打开帮助文件,比如用键盘打开***.chm文件。因为有事鼠标不好用,你要保证键盘可以用。
发表于 2004-8-12 16:48:01 | 显示全部楼层 来自 湖北武汉

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

"请问组合键能够识别吗? "
"谢谢!"
   
   
   
可以做一个隐藏菜单把要用的组合键都定义在里面
发表于 2005-8-7 15:45:03 | 显示全部楼层 来自 新疆乌鲁木齐

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

bigrice wrote:
Jack Little:”同志们,我代表Mathworks公司向你们致以崇高的敬意,你们用我们开发的软件做出了我们做不到的事情。”
  
哈哈,谢谢楼上几位大牛,大家继续讨论!
又删掉了几个垃圾贴,再顶出来,看到前辈所作的工作,有一种羞愧得想死掉的感觉.很羡慕大米,你当版主时逢几大高手创作力最旺盛的时期,每天一定都会迫不及待地打开simwe的网页...
真是令人向往...:)
(同时,也希望除非有一定的见解,否则别发"好","顶","佩服"之类的垃圾贴,对这些我不会手软...:D)
发表于 2010-12-27 22:27:29 | 显示全部楼层 来自 上海
虽然有些古老了,但是确实现在需要用

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2011-10-30 21:33:21 | 显示全部楼层 来自 台湾
本帖最后由 ChaChing 于 2011-10-30 21:36 编辑

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

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

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

点评

http://www.chinavib.com/thread-106608-1-1.html  发表于 2011-11-6 21:34
回复 不支持

使用道具 举报

发表于 2011-10-31 01:20:48 | 显示全部楼层 来自 英国
ChaChing 发表于 2011-10-30 21:33
虽然印象中好像看过这些属性, 但刚刚怎都没help到figure的"CurrentKey"及"HelpFcn"属性 ?? 跟版本有关吗?
C ...

比较一下:

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


  2.         Alphamap = [ (1 by 64) double array]
  3.         CloseRequestFcn = closereq
  4.         Color = [0.8 0.8 0.8]
  5.         Colormap = [ (64 by 3) double array]
  6.         CurrentAxes = [174.005]
  7.         CurrentCharacter =
  8.         CurrentObject = []
  9.         CurrentPoint = [0 0]
  10.         DockControls = on
  11.         FileName =
  12.         IntegerHandle = on
  13.         InvertHardcopy = on
  14.         KeyPressFcn =
  15.         KeyReleaseFcn =
  16.         MenuBar = figure
  17.         Name =
  18.         NextPlot = add
  19.         NumberTitle = on
  20.         PaperUnits = centimeters
  21.         PaperOrientation = portrait
  22.         PaperPosition = [0.634517 6.34517 20.3046 15.2284]
  23.         PaperPositionMode = manual
  24.         PaperSize = [20.984 29.6774]
  25.         PaperType = A4
  26.         Pointer = arrow
  27.         PointerShapeCData = [ (16 by 16) double array]
  28.         PointerShapeHotSpot = [1 1]
  29.         Position = [360 502 560 420]
  30.         Renderer = painters
  31.         RendererMode = auto
  32.         Resize = on
  33.         ResizeFcn =
  34.         SelectionType = normal
  35.         ToolBar = auto
  36.         Units = pixels
  37.         WindowButtonDownFcn =
  38.         WindowButtonMotionFcn =
  39.         WindowButtonUpFcn =
  40.         WindowKeyPressFcn =
  41.         WindowKeyReleaseFcn =
  42.         WindowScrollWheelFcn =
  43.         WindowStyle = normal
  44.         WVisual = 00 (RGB 32  GDI, Bitmap, Window)
  45.         WVisualMode = auto

  46.         BeingDeleted = off
  47.         ButtonDownFcn =
  48.         Children = [174.005]
  49.         Clipping = on
  50.         CreateFcn =
  51.         DeleteFcn =
  52.         BusyAction = queue
  53.         HandleVisibility = on
  54.         HitTest = on
  55.         Interruptible = on
  56.         Parent = [0]
  57.         Selected = off
  58.         SelectionHighlight = on
  59.         Tag =
  60.         Type = figure
  61.         UIContextMenu = []
  62.         UserData = []
  63.         Visible = on
复制代码


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

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



  2.         Alphamap = [ (1 by 64) double array]
  3.         BackingStore = on
  4.         CloseRequestFcn = closereq
  5.         Color = [0.8 0.8 0.8]
  6.         Colormap = [ (64 by 3) double array]
  7.         CurrentAxes = [174.005]
  8.         CurrentCharacter =
  9.         CurrentKey = alt
  10.         CurrentModifier = [ (1 by 0) cell array]
  11.         CurrentObject = []
  12.         CurrentPoint = [0 0]
  13.         DithermapWarning: figure Dithermap is no longer useful with TrueColor displays,
  14. and will be removed in a future release.
  15. = [ (64 by 3) double array]
  16.         DithermapModeWarning: figure DithermapMode is no longer useful with TrueColor displays,
  17. and will be removed in a future release.
  18. = manual
  19.         DockControls = on
  20.         DoubleBuffer = on
  21.         FileName =
  22.         FixedColorsWarning: figure FixedColors produces a warning and will be removed in a future release
  23. = [ (10 by 3) double array]
  24.         HelpFcn =
  25.         HelpTopicMap =
  26.         IntegerHandle = on
  27.         InvertHardcopy = on
  28.         KeyPressFcn =
  29.         KeyReleaseFcn =
  30.         MenuBar = figure
  31.         MinColormapWarning: figure MinColormap produces a warning and will be removed in a future release
  32. = [64]
  33.         Name =
  34.         JavaFrameWarning: figure JavaFrame property will be obsoleted in a future release. For more
  35. information see the JavaFrame resource on the MathWorks web site.
  36. = [ (1 by 1) com.mathworks.hg.peer.FigurePeer array]
  37.         NextPlot = add
  38.         NumberTitle = on
  39.         PaperUnits = centimeters
  40.         PaperOrientation = portrait
  41.         PaperPosition = [0.634517 6.34517 20.3046 15.2284]
  42.         PaperPositionMode = manual
  43.         PaperSize = [20.984 29.6774]
  44.         PaperType = A4
  45.         Pointer = arrow
  46.         PointerShapeCData = [ (16 by 16) double array]
  47.         PointerShapeHotSpot = [1 1]
  48.         Position = [360 502 560 420]
  49.         OuterPosition = [352 494 576 512]
  50.         ActivePositionProperty = position
  51.         PrintTemplate = []
  52.         ExportTemplate = []
  53.         Renderer = painters
  54.         RendererMode = auto
  55.         Resize = on
  56.         ResizeFcn =
  57.         SelectionType = normal
  58.         ToolBar = auto
  59.         Units = pixels
  60.         WaitStatus = []
  61.         WindowButtonDownFcn =
  62.         WindowButtonMotionFcn =
  63.         WindowButtonUpFcn =
  64.         WindowKeyPressFcn =
  65.         WindowKeyReleaseFcn =
  66.         WindowScrollWheelFcn =
  67.         WindowStyle = normal
  68.         WVisual = 00 (RGB 32  GDI, Bitmap, Window)
  69.         WVisualMode = auto
  70.         UseHG2 = off

  71.         BeingDeleted = off
  72.         PixelBounds = [0 0 560 420]
  73.         ButtonDownFcn =
  74.         Children = [174.005]
  75.         Clipping = on
  76.         CreateFcn =
  77.         DeleteFcn =
  78.         BusyAction = queue
  79.         HandleVisibility = on
  80.         HelpTopicKey =
  81.         HitTest = on
  82.         Interruptible = on
  83.         Parent = [0]
  84.         Selected = off
  85.         SelectionHighlight = on
  86.         Serializable = on
  87.         Tag =
  88.         Type = figure
  89.         UIContextMenu = []
  90.         UserData = []
  91.         ApplicationData = [ (1 by 1) struct array]
  92.         Behavior = [ (1 by 1) struct array]
  93.         Visible = on
  94.         XLimInclude = on
  95.         YLimInclude = on
  96.         ZLimInclude = on
  97.         CLimInclude = on
  98.         ALimInclude = on
  99.         IncludeRenderer = on
复制代码


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

  5. ans =

  6.     'BackingStore'
  7.     'CurrentKey'
  8.     'CurrentModifier'
  9.     'Dithermap'
  10.     'DithermapMode'
  11.     'DoubleBuffer'
  12.     'FixedColors'
  13.     'HelpFcn'
  14.     'HelpTopicMap'
  15.     'MinColormap'
  16.     'JavaFrame'
  17.     'OuterPosition'
  18.     'ActivePositionProperty'
  19.     'PrintTemplate'
  20.     'ExportTemplate'
  21.     'WaitStatus'
  22.     'UseHG2'
  23.     'PixelBounds'
  24.     'HelpTopicKey'
  25.     'Serializable'
  26.     'ApplicationData'
  27.     'Behavior'
  28.     'XLimInclude'
  29.     'YLimInclude'
  30.     'ZLimInclude'
  31.     'CLimInclude'
  32.     'ALimInclude'
  33.     'IncludeRenderer'
复制代码




点评

Thanks  发表于 2011-10-31 16:50

评分

1

查看全部评分

回复 不支持

使用道具 举报

发表于 2011-11-6 19:48:28 | 显示全部楼层 来自 上海
楼上的比较细心。这些隐藏的属性还是很有用的,值得大家细细研究。
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-10-6 07:50 , Processed in 0.070980 second(s), 22 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表