虚拟键盘的消息队列,进程间GetKeyboardState

yikoda 2014-10-15 02:48:15
在一个进程里改变键盘状态如大小写,在第二个进程里,第一次是取不到正确的大小写状态的。

查了好多资料,看到一句这个话 :GetKeyState returns the virtual key state. In other words, GetKeyState reports the state of the keyboard based on the messages you have retrieved from your input queue. This is not the same as the physical keyboard state:
•
If the user has typed ahead, GetKeyState doesn't report those changes until you use the PeekMessage function or the GetMessage function to retrieve the message from your input queue.

•
If the user has switched to another program, then the GetKeyState function will not see the input that the user typed into that other program, since that input was not sent to your input queue.

在两个进程中,虚拟键盘是两个消息队列,新的进程在消息队列没有过来之前,是收不到正确的键盘消息,,希望能给有大神指点,可以手动的在期望的进程里,让消息队列和虚拟键盘连接起来。。。表达的不太好。

...全文
330 4 打赏 收藏 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-10-15
  • 打赏
  • 举报
回复
Key Status While processing a keyboard message, an application may need to determine the status of another key besides the one that generated the current message. For example, a word-processing application that allows the user to press shift+end to select a block of text must check the status of the shift key whenever it receives a keystroke message from the end key. The application can use the GetKeyState function to determine the status of a virtual key at the time the current message was generated; it can use the GetAsyncKeyState function to retrieve the current status of a virtual key. The keyboard layout maintains a list of names. The name of a key that produces a single character is the same as the character produced by the key. The name of a noncharacter key such as tab and enter is stored as a character string. An application can retrieve the name of any key from the device driver by calling the GetKeyNameText function.
赵4老师 2014-10-15
  • 打赏
  • 举报
回复
GetAsyncKeyState The GetAsyncKeyState function determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState. SHORT GetAsyncKeyState( int vKey // virtual-key code ); Parameters vKey Specifies one of 256 possible virtual-key codes. For more information, see Virtual-Key Codes. Windows NT: You can use left- and right-distinguishing constants to specify certain keys. See the Remarks section for further information. Return Values If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. The return value is zero if a window in another thread or process currently has the keyboard focus. Windows 95: Windows 95 does not support the left- and right-distinguishing constants. If you call GetAsyncKeyState with these constants, the return value is zero. Remarks The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling GetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped. You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the shift, ctrl, or alt keys without distinguishing between left and right. Windows NT: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys. Code Meaning VK_LSHIFT VK_RSHIFT VK_LCONTROL VK_RCONTROL VK_LMENU VK_RMENU These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. Windows CE: The GetAsyncKeyState function supports the left and right virtual key constants, so you can determine whether the left key or the right key was pressed. These constants are VK_LCONTROL, VK_RCONTROL, VK_LMENU, VK_RMENU, VK_LSHIFT, and VK_RSHIFT. The least significant bit of the return value is not valid in Windows CE, and should be ignored. GetAsyncKeyState will return the current key state even if a window in another thread or process currently has the keyboard focus. You can also use the VK_LBUTTON virtual-key code constant to determine the state of the stylus tip, (up/down), on the touch-screen. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winuser.h. Import Library: Use user32.lib. See Also Keyboard Input Overview, Keyboard Input Functions, GetKeyboardState, GetKeyState,GetSystemMetrics, MapVirtualKey, SetKeyboardState
赵4老师 2014-10-15
  • 打赏
  • 举报
回复
GetKeyState The GetKeyState function retrieves the status of the specified virtual key. The status specifies whether the key is up, down, or toggled (on, off — alternating each time the key is pressed). SHORT GetKeyState( int nVirtKey // virtual-key code ); Parameters nVirtKey Specifies a virtual key. If the desired virtual key is a letter or digit (A through Z, a through z, or 0 through 9), nVirtKey must be set to the ASCII value of that character. For other keys, it must be a virtual-key code. If a non-English keyboard layout is used, virtual keys with values in the range ASCII A through Z and 0 through 9 are used to specify most of the character keys. For example, for the German keyboard layout, the virtual key of value ASCII O (0x4F) refers to the "o" key, whereas VK_OEM_1 refers to the "o with umlaut" key. Return Values The return value specifies the status of the given virtual key, as follows: If the high-order bit is 1, the key is down; otherwise, it is up. If the low-order bit is 1, the key is toggled. A key, such as the caps lock key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled. Remarks The key status returned from this function changes as a given thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information. An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated. To retrieve state information for all the virtual keys, use the GetKeyboardState function. An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the nVirtKey parameter. This gives the status of the shift, ctrl, or alt keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys. VK_LSHIFT VK_RSHIFT VK_LCONTROL VK_RCONTROL VK_LMENU VK_RMENU These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. Windows CE: The GetKeyState function can only be used to check the down state of the following virtual keys: VK_CONTROL VK_SHIFT VK_MENU VK_LCONTROL VK_LSHIFT VK_LMENU VK_RCONTROL VK_RSHIFT VK_RMENU GetKeyState can only be used to check the toggled state of the VK_CAPITAL virtual key. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winuser.h. Import Library: Use user32.lib. See Also Keyboard Input Overview, Keyboard Input Functions, GetAsyncKeyState, GetKeyboardState, MapVirtualKey, SetKeyboardState GetKeyboardState The GetKeyboardState function copies the status of the 256 virtual keys to the specified buffer. BOOL GetKeyboardState( PBYTE lpKeyState // pointer to array to receive status data ); Parameters lpKeyState Pointer to the 256-byte array that will receive the status data for each virtual key. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, callGetLastError. Remarks An application can call this function to retrieve the current status of all the virtual keys. The status changes as a thread removes keyboard messages from its message queue. The status does not change as keyboard messages are posted to the thread's message queue, nor does it change as keyboard messages are posted to or retrieved from message queues of other threads. (Exception: Threads that are connected viaAttachThreadInput share the same keyboard state.) When the function returns, each member of the array pointed to by the lpKeyState parameter contains status data for a virtual key. If the high-order bit is 1, the key is down; otherwise, it is up. If the low-order bit is 1, the key is toggled. A key, such as the caps lock key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled. To retrieve status information for an individual key, use the GetKeyState function. To retrieve the current state for an individual key regardless of whether the corresponding keyboard message has been retrieved from the message queue, use the GetAsyncKeyState function An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL and VK_MENU as indices into the array pointed to by lpKeyState. This gives the status of the shift, ctrl, or alt keys without distinguishing between left and right. An application can also use the following virtual-key code constants as indices to distinguish between the left and right instances of those keys. VK_LSHIFT VK_RSHIFT VK_LCONTROL VK_RCONTROL VK_LMENU VK_RMENU These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in winuser.h. Import Library: Use user32.lib. See Also Keyboard Input Overview, Keyboard Input Functions, GetKeyState, GetAsyncKeyState, MapVirtualKey, SetKeyboardState
yikoda 2014-10-15
  • 打赏
  • 举报
回复
换成GetKeyState竟然取到了正确值,对比上面GetKeyboardState的那个错误值,顿时也是醉了。。 GetKeyState: msdn:The key status returned from this function changes as a thread reads key messages from its message queue ->reads key messages from its message queue 从自己的消息队列么? 那为啥 GetKeyState可以取到,GetKeyboardState取不到。。
内容概要:本文系统研究了基于雅可比伪逆迭代的双臂协同轨迹规划与跟踪误差收敛性问题,结合机械臂正向与逆向运动学建模、蒙特卡洛法分析工作空间、笛卡尔空间内的圆弧轨迹生成等关键技术,利用Matlab实现了双臂系统的协同控制与轨迹跟踪仿真。重点探讨了雅可比矩阵伪逆法在解决冗余自由度机械臂逆运动学问题中的应用,深入分析了轨迹跟踪过程中误差的收敛特性,并通过仿真实验验证了该方法在复杂任务场景下的有效性、稳定性与鲁棒性,为多臂机器人在工业自动化、精密操作等领域的协同作业提供了理论依据与技术支持。; 适合人群:具备机器人学、自动控制理论基础及Matlab编程能力的科研人员与工程技术人员,特别适合从事机械臂控制、轨迹规划、多机器人协同等方向的硕士、博士研究生及相关领域研究人员。; 使用场景及目标:①掌握基于雅可比伪逆法的机械臂逆运动学求解原理与实现方法;②理解双臂系统在笛卡尔空间中协同轨迹规划的机制;③分析并优化轨迹跟踪过程中的误差收敛性能;④为多机器人系统在复杂动态环境下的高精度协同控制提供算法设计与仿真验证支持。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,按照文档目录循序渐进地学习,重点关注算法实现细节、仿真参数设置与结果分析部分,同时可进一步探索将智能优化算法或深度学习方法引入轨迹规划与误差补偿的研究方向。

15,465

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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