Results 1 to 13 of 13

Thread: chr problem !!!

  1. #1
    Hyperactive Member
    Join Date
    May 12
    Posts
    338

    chr problem !!!

    i use the following code for virtual key code conversion

    Code:
    If code = HC_ACTION And wParam <> 257 Then
            CopyMemory kybd, ByVal lParam, Len(kybd)
           Form1.Text1.Text = Form1.Text1.Text & Chr(kybd.vkCode)
            myfunc = CallNextHookEx(Hook, code, wParam, lParam)
            Else
          If code = HC_ACTION And wParam <> 13 Then
            CopyMemory kybd, ByVal lParam, Len(kybd)
           Form1.Text1.Text = Form1.Text1.Text & "enter key"
           ElseIf code < 0 Then
            myfunc = CallNextHookEx(Hook, code, wParam, lParam)
        End If
        End If
    but it does not give any symbol for key 13 (enterkey) , how to do it ???

    i want it write enterkey instead of blank symbol
    Last edited by useruseronline; Aug 18th, 2012 at 07:18 PM.

  2. #2
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,255

    Re: chr problem !!!

    I think you should replace

    If code = HC_ACTION And wParam <> 13 Then

    with

    If code = HC_ACTION And wParam = 13 Then

  3. #3
    PowerPoster
    Join Date
    Jul 06
    Location
    Maldon, Essex. UK
    Posts
    5,143

    Re: chr problem !!!

    I think you should split the code up so it describes exactly what you want to do
    Code:
    If code = HC_ACTION Then
        CopyMemory kybd, ByVal lParam, Len(kybd)
        Select Case wParam
            Case 13
                Form1.Text1.Text = Form1.Text1.Text & "enter key"
            Case Else      
                Form1.Text1.Text = Form1.Text1.Text & Chr(kybd.vkCode)
        End Select
    End If
    myfunc = CallNextHookEx(Hook, code, wParam, lParam)
    As far as I understand Virtual Key Codes are in the range 1 to &HFF (255) so there's no need to check for wParam to be greater than 256.
    Using the Select Case construct enables you to easily add other 'special cases' if and when required (eg if the user has pressed F1 you wont see anything added to Form1.Text1.Text)

  4. #4
    Hyperactive Member
    Join Date
    May 12
    Posts
    338

    Re: chr problem !!!

    can u please give an example code ... how to but select case ...

  5. #5
    PowerPoster
    Join Date
    Jul 06
    Location
    Maldon, Essex. UK
    Posts
    5,143

    Re: chr problem !!!

    Post #3 is an example. What more do you need ?

  6. #6
    Hyperactive Member
    Join Date
    May 12
    Posts
    338

    Re: chr problem !!!

    its not working .... thats why i asked for example

  7. #7
    PowerPoster
    Join Date
    Jul 06
    Location
    Maldon, Essex. UK
    Posts
    5,143

    Re: chr problem !!!

    What does 'its not working' mean ?

  8. #8
    Hyperactive Member
    Join Date
    May 12
    Posts
    338

    Re: chr problem !!!

    it still gives blank symbol for enter key ..

  9. #9
    Hyperactive Member
    Join Date
    May 12
    Posts
    338

    Re: chr problem !!!

    it still gives blank symbol for enter key ..

  10. #10
    Hyperactive Member
    Join Date
    May 12
    Posts
    338

    Re: chr problem !!!

    how to ...

  11. #11
    PowerPoster
    Join Date
    Feb 12
    Location
    West Virginia
    Posts
    4,957

    Re: chr problem !!!

    There is no symbol for the enter key it is a control key for a carriage return.

    The sample doogle posted would put the words "enter key" in your text box.

  12. #12
    Frenzied Member
    Join Date
    Jan 09
    Location
    Watch Window(Shift+f9)
    Posts
    1,431

    Re: chr problem !!!

    Try the following !
    Code:
    If code = HC_ACTION And wParam <> 257 Then
            CopyMemory kybd, ByVal lParam, Len(kybd)
           Form1.Text1.Text = Form1.Text1.Text & Chr(kybd.vkCode)
            myfunc = CallNextHookEx(Hook, code, wParam, lParam)
            Else
          If code = HC_ACTION And wParam = vbKeyReturn Then
            CopyMemory kybd, ByVal lParam, Len(kybd)
           Form1.Text1.Text = Form1.Text1.Text & "enter key"
           ElseIf code < 0 Then
            myfunc = CallNextHookEx(Hook, code, wParam, lParam)
        End If
        End If

  13. #13
    PowerPoster
    Join Date
    Jul 06
    Location
    Maldon, Essex. UK
    Posts
    5,143

    Re: chr problem !!!

    Actually, looking at the original Code I can't see how it works at all.

    I assume the code is in a Keyboard Hook routine in which case wParam is the Virtual-key Code and lParam is the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag. (see: http://msdn.microsoft.com/en-us/libr...v=vs.85).aspx) I think I'm surprised that the IDE doesn't crash when the CopyMemory is executed.

    In the original code in Post #1 (and the code in Post #12) the second If statement is only executed when HC_ACTION <> 0 or wParam = 257. Since wParam will never exceed 255 the second If statement will never be executed.

Posting Permissions

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