Results 1 to 11 of 11

Thread: How to Detect a Key Pressed from Outside my VB App like Getting the Cursor Positon

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    India, Chennai
    Posts
    121

    Lightbulb How to Detect a Key Pressed from Outside my VB App like Getting the Cursor Positon

    Hi,
    With the GetCursorPos API we can get the Position of the Cursor even when a VB APP is not in Focus. ie., wherever the mouse is moved the Mouse Position can be traced with the GetCursorpos API. Is there any API to trace out the Keyboard hit events and trace the value of Key Pressed. Say suppose if the Enter Key is Pressed I should get a value like the KeyAscii Value. Is it Possible... If Possible then can anyone explain it to me with a working Example... I will be greatly thankful to you.

  2. #2
    New Member
    Join Date
    Mar 2001
    Location
    The Netherlands
    Posts
    7
    You can use the GetAsyncKeyState() API Function.
    Example:

    Code:
    Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
    
    Dim State as Integer
    State = GetAsyncKeyState(vbKeyH)
    If State And &H8000 Then
        'Key is pressed
    Else
        'H Key is not pressed
    End If

  3. #3
    Megatron
    Guest
    The hook method is more accurate, but the disadvantage, as Vlatko pointed out, is that it's harder to do.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    India, Chennai
    Posts
    121

    It's giving a Error, Invalid Addressof TimerProc...

    Hi Vlatko,
    I tried your Program, It's giving me a error called Invalid AddressOf usage (something like that). What should I do now. And from where can I get the Value of Keypressed and in What Format. Whether Keycode or KeyAscii, Or anyother Different value. Please help me...
    Anyway thanks for ur code....

  5. #5
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Note that the first code (with the TimerProc) has to be in a module and not in a form.

    Put this declarations in the module also.
    Code:
    Public Cnt As Long, sSave As String, sOld As String, Ret As String
    The value you get is a character not ASCII code but the letter.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    India, Chennai
    Posts
    121

    How about Alt, Ctrl and Shift Keys...

    Hi Vlatko,
    If I pressed the Normal Character Keys and the Number Keys then it'll give a Character then how about about the Mask keys namely Alt, Ctrl and Shift Keys. Also how about the Function Keys... Have any Idea....

  7. #7
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Search the web and the VB sites. There is a lot of code for fully functional keyloggers.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  8. #8
    Megatron
    Guest
    Planet-Source-Code.com has some examples. Click here to view them.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    India, Chennai
    Posts
    121

    Cool Thanks Megatron I got It....

    Hi Megatron,
    I got them and thanks for it. I've not yet tried them. After trying I'll contact you. Can u give ur mail id. It would be easy for me to contact you there.
    Regards

  10. #10
    Lively Member eric445's Avatar
    Join Date
    Aug 2000
    Location
    Seattle, WA (USA)
    Posts
    70

    Question Get window name?

    Is there any way yo get the name of the window text is typed into?

  11. #11
    Megatron
    Guest

    Re: Thanks Megatron I got It....

    Originally posted by lvramanan
    Hi Megatron,
    I got them and thanks for it. I've not yet tried them. After trying I'll contact you. Can u give ur mail id. It would be easy for me to contact you there.
    Regards
    Sure, it's [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width