Results 1 to 5 of 5

Thread: Help with SendKeys statement

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Help with SendKeys statement

    This entire snippet errors out with "Argument not optional" when I run this code. I put in the code as instructed, as seen below:


    Code:
    Private Sub Form_KeyPress(KeyAscii As Integer)
        If SendKeys = "^C" Then    'VB errors out with "Expected: Then Or GoTo without the =
            MsgBox "Control+C pressed"
        End If
    End Sub

    I thought it might be that the Wait variable was missing, but I looked it up on MSDN, and it says that variable is optional. I tried it anyways, and I still get the same error. What am I doing wrong?

  2. #2
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    SendKeys is not a function... it does nto have a return value, so SendKeys = "^C" is an invalid statement
    Leather Face is comin...


    MCSD

  3. #3
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    What are you trying to do, send some key strokes (this is what send keys does) or detect keys being pressed?
    Leather Face is comin...


    MCSD

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    SendKeys is used to send key sequences to your PC, not to determine which key was pressed which seems to be what you are tring to do. Here is an example that determines which keys were pressed.
    VB Code:
    1. Private Sub Text1_KeyDown(KeyCode As Integer, _
    2.       Shift As Integer)
    3.    ShiftKey = Shift And 7
    4.    Select Case ShiftKey
    5.       Case 1 ' or vbShiftMask
    6.          Print "You pressed the SHIFT key."
    7.       Case 2 ' or vbCtrlMask
    8.          Print "You pressed the CTRL key."
    9.       Case 4 ' or vbAltMask
    10.          Print "You pressed the ALT key."
    11.       Case 3
    12.          Print "You pressed both SHIFT and CTRL."
    13.       Case 5
    14.          Print "You pressed both SHIFT and ALT."
    15.       Case 6
    16.          Print "You pressed both CTRL and ALT."
    17.       Case 7
    18.          Print "You pressed SHIFT, CTRL, and ALT."
    19.       End Select
    20. End Sub

  5. #5
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    SENDKEYS sends key strokes. You can't test SendKeys to see what the user typed.

    You CAN check KeyAscii to see what the user typed.

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