变态的需求:键盘输入

yingbinchina 2009-11-26 08:42:25
接到任务,在一个主Form中会调出其它的子Form,在这些子Form中的可输入控件中,比如EditBox,按键Shift+Esc,
输入波浪线(本来波浪线是在撇的上边,也就是shift+撇,可是键盘上没有做这个键,设计有问题),请大家帮忙。

由此问题,我再引申出二个问题:
1. 据我所知,windows消息可以在主消息循环wndpro中重新发配,那么对于这种shift+Esc,在WndPro中如何截获,
难道是第一次wm_keydow,存储键值,在第二次wm_keydown,存储键值,再判断吗?不太清楚了。

2. 如果要画一条线,要求在按住shift的情况下,画线就画红线,那么又如何截取消息呢?WM_MOUSEMOVE + WM_KEYDOWN?

谢谢大家的回复。
...全文
148 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
lllyyy2403 2009-11-30
  • 打赏
  • 举报
回复
你提到的也就是shif键的状态消息而已,这有专门的表示常量的,好象是ShiftSate吧,具体忘了。这种键盘编程不难的,不就是一个HOOK编程吗?
yingbinchina 2009-11-30
  • 打赏
  • 举报
回复
自己搞定了。

方法:将当前线程的ID,作为HOOK的参数传入。
yingbinchina 2009-11-29
  • 打赏
  • 举报
回复

有人给你回信呀。~~~
yingbinchina 2009-11-27
  • 打赏
  • 举报
回复
DING
yingbinchina 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 behard 的回复:]
不是很理解楼主不明白什么东西或者想问什么东西

您的具体需求是什么?

一般控件的 MouseMove、KeyDown、KeyUp 事件中都有 TShiftState 类型的参数知道键盘的状态

TShiftState type

TShiftState indicates the state of the Alt, Ctrl, and Shift keys and the mouse buttons.

Unit

Classes

typedef Set <Classes__1, ssShift, ssDouble>  TShiftState;

Description

The TShiftState type is used by key-event and mouse-event handlers to determine the state of the Alt, Ctrl, and Shift keys and the state of the mouse buttons when the event occurred.  It is a set of flags that indicate the following:

Value Meaning

ssShift The Shift key is held down.
ssAlt The Alt key is held down.
ssCtrl The Ctrl key is held down.
ssLeft The left mouse button is held down.
ssRight The right mouse button is held down.
ssMiddle The middle mouse button is held down.
ssDouble The mouse was double-clicked.
[/Quote]

为了简化我的需求,我重新描述一下我的问题。
就是按键shift+esc, 在form中的编辑框中输入波浪线。


xjq2003 2009-11-27
  • 打赏
  • 举报
回复
来顶一下
yingbinchina 2009-11-27
  • 打赏
  • 举报
回复
首先设置窗体属性:keyprew = true
然后:

void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Shift.Contains(ssShift) && Key==VK_ESCAPE)
{
keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT,0), KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_OEM_3, MapVirtualKey(VK_OEM_3,0), KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_OEM_3, MapVirtualKey(VK_OEM_3,0), KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT,0), KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}
}

以上是我自己试验出来的,可以用。供大家参考。

现在问题是:我如何利用主form来向子form发命令,让在“子”Form中shift+esc出现波浪线呢?
当然不要在子form中添加上边的代码,因为子Form很多。
bingyu_2008 2009-11-27
  • 打赏
  • 举报
回复
mark,学习
Behard 2009-11-26
  • 打赏
  • 举报
回复
不是很理解楼主不明白什么东西或者想问什么东西

您的具体需求是什么?

一般控件的 MouseMove、KeyDown、KeyUp 事件中都有 TShiftState 类型的参数知道键盘的状态

TShiftState type

TShiftState indicates the state of the Alt, Ctrl, and Shift keys and the mouse buttons.

Unit

Classes

typedef Set<Classes__1, ssShift, ssDouble> TShiftState;

Description

The TShiftState type is used by key-event and mouse-event handlers to determine the state of the Alt, Ctrl, and Shift keys and the state of the mouse buttons when the event occurred. It is a set of flags that indicate the following:

Value Meaning

ssShift The Shift key is held down.
ssAlt The Alt key is held down.
ssCtrl The Ctrl key is held down.
ssLeft The left mouse button is held down.
ssRight The right mouse button is held down.
ssMiddle The middle mouse button is held down.
ssDouble The mouse was double-clicked.
yingbinchina 2009-11-26
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 yeyanbin 的回复:]
C/C++ code
HOOKPROC KeyboardProc(int iCode,WPARAM wParam, LPARAM lParam);constint KeyPressMask=0x80000000;
C/C++ code
HOOKPROC KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)

{if(((DWORD)lParam&0x40000000)&&(HC_ACTION==nCode))

{int iShift=GetKeyState(0x10);bool bShift=((iShift&KeyPressMask)==KeyPressMask);switch(wParam)
{// ESC F1~F12case VK_ESCAPE:break;case VK_F1:break;
... ...
}
}return (HOOKPROC)CallNextHookEx(hHook,nCode,wParam,lParam);
}
[/Quote]

没有编写过HOOK程序,能否给个例程,谢谢。email:yingbinchina@126.com

KeyboardProc是在什么地方调用呀?呵呵
YeBinYe 2009-11-26
  • 打赏
  • 举报
回复

HOOKPROC KeyboardProc(int iCode,WPARAM wParam, LPARAM lParam);
const int KeyPressMask=0x80000000;


HOOKPROC KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)

{

if(((DWORD)lParam&0x40000000)&&(HC_ACTION==nCode))

{

int iShift=GetKeyState(0x10);
bool bShift=((iShift&KeyPressMask)==KeyPressMask);
switch(wParam)
{
// ESC F1~F12
case VK_ESCAPE:
break;
case VK_F1:
break;
... ...
}
}
return (HOOKPROC)CallNextHookEx(hHook,nCode,wParam,lParam);
}
YeBinYe 2009-11-26
  • 打赏
  • 举报
回复
键盘Hook编程,很容易实现!
haiandj 2009-11-26
  • 打赏
  • 举报
回复
虚拟按键

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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