Results 1 to 8 of 8

Thread: Keys

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    FL
    Posts
    76

    Thumbs up

    Does anyone know how to make the computer press a key without you toughing the keyboard when you click on a button?
    Exp: you click a button and the computer presses the print screen key

  2. #2
    Lively Member
    Join Date
    May 1999
    Location
    KC
    Posts
    72
    Use SendKeys, eg:

    SendKeys("{PRTSC}")

  3. #3
    Junior Member
    Join Date
    Jun 2000
    Location
    Manchester, England
    Posts
    28
    You can use the SendKeys function to simulate keystrokes, however you can't use SendKeys to operate the PrintScreen key for any application! If this is what you are trying to achieve, you might have to think about using the clipboard or some other way, if your example was just an example and you need to know about SendKeys, let me know.
    We watch in reverence as Narcissus is turned to a flower.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Location
    FL
    Posts
    76

    Cool sendkeys

    tell me more about sendkeys

  5. #5
    Junior Member
    Join Date
    Jun 2000
    Location
    Manchester, England
    Posts
    28
    You can use SendKeys to send key strokes to an application, for example if you were to create a Microsoft Word object and then activated a new document, you could write text to the document like this:

    SendKeys "Dear Sir,"

    It can be very useful, if you have MSDN help look it up if not let me know what you want to do and I will give you a solution.
    We watch in reverence as Narcissus is turned to a flower.

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up

    You also use the keybd_event API function istead of Sendkeys function.

  7. #7
    Guest
    There are some keys that you can not differenciate such as Left Ctrl, Right Ctrl, Left Shift and Right Shift. For this, you can use DirectInput.

  8. #8
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Smile

    With this code I can detect the Left/Right Shift and Left/Right Control key event

    Code:
    Option Explicit
    Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    Private Const VK_LCONTROL = &HA2
    Private Const VK_LSHIFT = &HA0
    Private Const VK_RSHIFT = &HA1
    Private Const VK_RCONTROL = &HA3
    
    Private Sub Timer1_Timer()
    If GetKeyState(VK_LSHIFT) < 0 Then
        MsgBox "L_SHIFT"
    ElseIf GetKeyState(VK_RSHIFT) < 0 Then
        MsgBox "R_SHIFT"
    ElseIf GetKeyState(VK_LCONTROL) < 0 Then
        MsgBox "L_Ctrl"
    ElseIf GetKeyState(VK_RCONTROL) < 0 Then
        MsgBox "R_Ctrl"
    End If
    End Sub

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