如果窗口未激活,则获取输入(Windows) [英] Getting input if the window is not active (Windows)

查看:315
本文介绍了如果窗口未激活,则获取输入(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短版本:



当窗口未激活时,如何在Windows中使用C ++ / C接收输入消息? >

背景信息



我目前正在使用不应依赖的输入系统在任何窗口,所以它可以例如



我的想法是创建一个不可见的窗口只接收消息,这可能使用HWND_MESSAGE作为hWndParent。它只接收输入消息时,它是活动,虽然,我不想要这。它应该总是接收输入(除非应用程序请求它不再这样做,例如因为它失去了焦点)。



我知道这是可能的,许多应用程序支持全局快捷方式(例如媒体播放器(播放控制)或即时通讯(打开联系人列表)),我只是不知道如何。你知道吗?

解决方案

选项:




  • 如果您需要注册,请注册HotKey 只需一个或几个热键

  • SetWindowsHookEx 与WH_KEYBOARD / WH_KEYBOARD_LL。当需要过滤多个或所有键盘事件时使用。然而,钩子代码需要在DLL(被加载到其他进程)中实现。您需要单独的32位和64位版本的DLL


Short version:

How can I receive input messages in Windows with C++/C when the window is not active?

Background information:

I'm currently working on an Input System that should not depend on any window, so it can e.g. be used in the console as well.

My idea is to create an invisible window only receiving messages, which is possible using HWND_MESSAGE as hWndParent. It only receives input messages when it's active though, and I don't want this. It should always receive input (unless the application requests it no longer does so, e.g. because it lost focus).

I know this is possible somehow, many applications support global shortcuts (e.g. media players (playback control) or instant messengers (opening the contact list)), I just don't know how. Do you know?

解决方案

Options:

  • RegisterHotKey if you need to register just one or a few hotkeys
  • SetWindowsHookEx with WH_KEYBOARD / WH_KEYBOARD_LL. Use when you need to filter many or all keyboard events. However, the hook code needs to be implemented in a DLL (which is loaded into other processes). You need separate 32 bit and 64 bit versions of the DLL

这篇关于如果窗口未激活,则获取输入(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆