Results 1 to 4 of 4

Thread: Sendkeys

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2003
    Location
    Worcester, MA
    Posts
    782

    Sendkeys

    I want to use Sendkeys to do something like this

    VB Code:
    1. If keycode = 68 Then
    2. SendKeys "hello"
    3. End If

    The problem is thar i want this to work even if the form doesnt have focus. How should I go about doing this?
    C#.net, VB, C++, Java, VS 2005/2008
    Dont' forget to rate posts that are helpful to you.

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    You could set up a timer to fire the SendKeys code or call it from every event that requires it.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345
    Do you also want to catch the key which is pressed when the form is out of focus? If so, you will have to register a hotkey
    VB Code:
    1. Private Const MOD_ALT = &H1
    2. Private Const MOD_CONTROL = &H2
    3. Private Const MOD_SHIFT = &H4
    4. Private Const PM_REMOVE = &H1
    5. Private Const WM_HOTKEY = &H312
    6. Private Type POINTAPI
    7.     x As Long
    8.     y As Long
    9. End Type
    10. Private Type Msg
    11.     hWnd As Long
    12.     Message As Long
    13.     wParam As Long
    14.     lParam As Long
    15.     time As Long
    16.     pt As POINTAPI
    17. End Type
    18. Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
    19. Private Declare Function UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
    20. Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
    21. Private Declare Function WaitMessage Lib "user32" () As Long
    22. Private bCancel As Boolean
    23. Private Sub ProcessMessages()
    24.     Dim Message As Msg
    25.     'loop until bCancel is set to True
    26.     Do While Not bCancel
    27.         'wait for a message
    28.         WaitMessage
    29.         'check if it's a HOTKEY-message
    30.         If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
    31.             'minimize the form
    32.             WindowState = vbMinimized
    33.         End If
    34.         'let the operating system process other events
    35.         DoEvents
    36.     Loop
    37. End Sub
    38. Private Sub Form_Load()
    39.     'KPD-Team 2000
    40.     'URL: [url]http://www.allapi.net/[/url]
    41.     'E-Mail: [email][email protected][/email]
    42.     Dim ret As Long
    43.     bCancel = False
    44.     'register the Ctrl-F hotkey
    45.     ret = RegisterHotKey(Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyF)
    46.     'show some information
    47.     Me.AutoRedraw = True
    48.     Me.Print "Press CTRL-F to minimize this form"
    49.     'show the form and
    50.     Show
    51.     'process the Hotkey messages
    52.     ProcessMessages
    53. End Sub
    54. Private Sub Form_Unload(Cancel As Integer)
    55.     bCancel = True
    56.     'unregister hotkey
    57.     Call UnregisterHotKey(Me.hWnd, &HBFFF&)
    58. End Sub
    Last edited by TomGibbons; Feb 9th, 2004 at 05:09 AM.

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Or maybe the SendMessage API?


    Has someone helped you? Then you can Rate their helpful post.

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