code:
  HC_ACTION、HC_NOREMOVE
wParam:
  virtual-key codeParam:Value Description
0-15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user's holding down the key.
16-23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
24 Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is 1 if the key is an extended key; otherwise, it is 0.
25-28 Reserved.
29 Specifies the context code. The value is 1 if the ALT key is down; otherwise, it is 0.
30 Specifies the previous key state. The value is 1 if the key is down before the message is sent; it is 0 if the key is up.
31 Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released.

解决方案 »

  1.   

    to goodhope:
    为什么我按一次键,怎么会触发两次事件呢?有时候还触发4次6次,为什么?
      

  2.   

    SetWindowsHookEx的最后一个参数指定为空即0就可以全局有效
      

  3.   

    键盘下、键盘上;ASCII字符键事件;
    会产生几次事件;
      

  4.   

    SetWindowsHookEx的最后一个参数指定为空即0
    只对你的程序所有线程有效,不能对别人的程序
    有效,是局部钩子;
    要使钩子对所有程序有效,必须制成.DLL 才行
      

  5.   

    BCB老兄说的对,用DLL吧!
    小解:
    const
      _keypressmask=$80000000;
    //如侦测ctrl+shift+B
    if ((lparam and _keypressmask)=0) and (getkeystate(vk_shift)<0) and (getkeystate(vk_control)<0) and (wparam=ord('B')) thenconst
                                               浪子(^_^)
      

  6.   

    BCB老兄说的对,用DLL吧!
    小解:
    const
      _keypressmask=$80000000;
    //如侦测ctrl+shift+B
    if ((lparam and _keypressmask)=0) and (getkeystate(vk_shift)<0) and (getkeystate(vk_control)<0) and (wparam=ord('B')) thenconst
                                               浪子(^_^)
      

  7.   

    谢谢bcb兄和sclxp兄
    我正是用的dll,挂的也是全局的钩子,但是可能由于dll本身的特性,它存储的变量发生变化,我在应用程序中调用钩子函数时向dll传送本应用程序当前窗体的句柄,dll接收到句柄之后存储在自己的变量中,当dll监测到有键盘事件发生时,通过该句柄通知窗体,如果该窗体是当前窗口,一点错误都没有,但是当该窗体为非活动窗体时,不正确。开始我也怀疑是钩子的问题,后来在dll中加测试语句,知道dll已经监测到键盘事件,但是没能返回消息。检测用来存储句柄的变量,发现变量的值变为0了,不知道怎么才能解决?
      

  8.   

    钩子问题 各人都有,我用局部鼠标钩子想截取 鼠标位置,
    然后在Edit1->Text上显示一下,很简单的事,运行时一旦
    鼠标离开了本窗口,就弹出“出现严重问题的错误”,
    只要取消EDit1->Text与访问窗口VCL有关的句子,什么问题就
    没有;难道我的新钩子中不能访问VCL 的属性?!