Win2000下锁定键盘和鼠标。 
在CSDN上看到一个未公开的API函数BlockInput,在user32.dll中,用它可以
轻易的锁定键盘和鼠标。BOOL __stdcall (*BlockInput)(BOOL Flag);
(FARPROC)BlockInput = GetProcAddress(GetModuleHandle(
"user32.dll"), "BlockInput");
if (BlockInput) BlockInput(TRUE); //这样就可以了_________________________________________________________
以上是另一位高手为我解答的"如何在2000中用VB实现键盘锁定",但是我真的是看不太明白,不知道具体应该怎么用,有谁能帮帮我吗?

解决方案 »

  1.   

    去看看我在VB API里对你那篇"怎样用才能使所有的键盘按键失效?就象死机一样?"
    的回复。
      

  2.   

    不懂么?很简单的
    这段代码的作用就是声明一个名叫"BlockInput"的函数,然后将这个函数的指针指向user32.dll库中的那个"BlockInput"接口。说白了,作用相当于以下代码:
    private declare function "BlockInput" Lib "user32.dll" (byval Flag as boolean) as boolean'我不知道这个API真正的定义,所以这个声明只是为了表达意思,不一定具有实际的意义
    public function API_BlockInput(Flag as boolean) as boolean
    API_BlockInput=blockinput(flag)
    end function以上代码和你给出的C代码原理上有差别,但实现的效果是一致的。
    当然你可以尝试用vb的AddressOf来模仿该代码的原理,但我没试过,而且有一定的危险性。
      

  3.   

    The BlockInput function blocks keyboard and mouse input events from reaching applications.?fBlock
    [in] Specifies the function's purpose. If this parameter is TRUE, keyboard and mouse input events are blocked. If this parameter is FALSE, keyboard and mouse events are unblocked. Note that only the thread that blocked input can successfully unblock input.If the function succeeds, the return value is nonzero.
    If input is already blocked, the return value is zero. To get extended error information, call GetLastError. Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    Private Sub Form_Activate()
        'KPD-Team 2000
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        DoEvents
        'block the mouse and keyboard input
        BlockInput True
        'wait 10 seconds before unblocking it
        Sleep 10000
        'unblock the mouse and keyboard input
        BlockInput False
    End Sub