初学者问题:我想用键盘激活一个自编的应用程序,有哪几种方法?

menb 2005-01-20 12:39:45
-
...全文
86 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gamezealot 2005-01-20
  • 打赏
  • 举报
回复
有2钟方法,一种是单键(消息)。另一种是系统键加其他键组合,具体可以看下MSDN上的说明。
RegisterHotKey是后一个的函数。MSDN里的一段:
There are two ways to associate a hot key with your app: you can use WM_SETHOTKEY to set a single hot key that activates your app, or you can use RegisterHotKey to register any number of hot keys that can do whatever you want. With WM_SETHOTKEY, the key is associated with your top-level window and main thread; RegisterHotKey works with any window and thread. Since WM_SETHOTKEY is the easy approach, I'll show you the other one—RegisterHotKey.
But before I do, here are some words of caution: a lot of people (myself included) use text editors like Emacs, which uses virtually every possible combination of Alt + Shift + Ctrl characters fathomable, and we folks get extremely irritated when some program comes along to take over even one of these keys. Imagine—you press Ctrl+Alt+S expecting to invoke regex-search (regular expression search), but instead you get some dialog appearing in the middle of your screen. Sheesh! It's very annoying. So at the least you should provide a way for users to change the hot key or turn it off completely.
// In CMyDialog::OnInitDialog
m_nIDHotKey = GlobalAddAtom("FileType2App");
RegisterHotKey(m_hWnd, m_nIDHotKey, MOD_WIN,
'A');
然后ON_MESSAGE(WM_HOTKEY, OnHotKey)
最后void CMyDialog::OnDestroy()
{
UnregisterHotKey(m_hWnd, m_nIDHotKey);
}
社会栋梁 2005-01-20
  • 打赏
  • 举报
回复
可以用钩子
再加载你的进程
老夏Max 2005-01-20
  • 打赏
  • 举报
回复
键盘HOOK!如果程序是已经运行的可以使用RegisterHotKey注册热键
kugou123 2005-01-20
  • 打赏
  • 举报
回复
用热键
http://www.xiaozhou.net/cooldog/blogview.asp?logID=78

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧