Results 1 to 7 of 7

Thread: [RESOLVED] Convert Letter To vbKey Equivalent ("a" > vbKeyA)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Resolved [RESOLVED] Convert Letter To vbKey Equivalent ("a" > vbKeyA)

    I am using PostMessage API to send text to a certain program.
    I've got my program to work when I use
    VB Code:
    1. PostMessage hWnd1, WM_KEYDOWN, vbKeyA, 0
    But I need to send a string that will be defined at runtime, so I need a way to do something like
    VB Code:
    1. PostMessage hWnd1, WM_KEYDOWN, "something", 0
    but that code doesn't work.
    I need to send a long value of each letter so I need to know how to convert a letter to its vbKey equivalent
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  2. #2

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Convert Letter To vbKey Equivalent ("a" > vbKeyA)

    I tried using WM_SETTEXT earlier when I was still using SendMessage API but it just set the title of the program.
    I'll try it out now with PostMessage
    EDIT:
    I got a 'Type Mismatch' error.
    What is the syntax for using WM_SETTEXT?
    I was using
    VB Code:
    1. PostMessage hWnd1, WM_SETTEXT, "a", 0
    But it doesn't even work with
    VB Code:
    1. PostMessage hWnd1, WM_SETTEXT, vbKeyA, 0
    Last edited by shirazamod; Apr 20th, 2006 at 06:28 AM.
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Convert Letter To vbKey Equivalent ("a" > vbKeyA)

    Well if you want do it with WM_KEYDOWN then the keycodes are the same as the Ascii values, but it'll all be in the same case:

    VB Code:
    1. Dim sText As String, N As Long
    2.  
    3. sText = "something"
    4.  
    5. For N = 1 to Len(sText)
    6.     PostMessage hWnd1, WM_KEYDOWN, Asc(Mid$(sText, N, 1)), 0
    7.     PostMessage hWnd1, WM_KEYUP, Asc(Mid$(sText, N, 1)), 0
    8. Next N
    Perhaps try WM_CHAR

  5. #5
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Convert Letter To vbKey Equivalent ("a" > vbKeyA)

    When using WM_SETTEXT you should be using it this way
    VB Code:
    1. PostMessage hwnd1, WM_SETTEXT, 0&, "Text that needs to be sent"
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Convert Letter To vbKey Equivalent ("a" > vbKeyA)

    you'd use WM_SETTEXT by sending the text to the edit box that you want to recieve the text
    VB Code:
    1. PostMessage lHwndEdit, WM_SETTEXT, 0&, ByVal "TEST"

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    South Africa
    Posts
    760

    Re: Convert Letter To vbKey Equivalent ("a" > vbKeyA)

    Thanks bushmobile, that sorted it out!
    If I helped you out, please consider adding to my reputation!

    -- "The faulty interface lies between the chair and the keyboard" --

    VB6 Programs By Me:
    ** Dictionary, Thesaurus & Rhyme-Generator In One ** WMP Recent Files List Editor ** Pretty Impressive Clock ** Extract Firefox History **

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