Results 1 to 8 of 8

Thread: KeyPress

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    New Jersey
    Posts
    334

    Post

    Hi,
    I did a test to see how the KeyPress function works. To test it, I used this:

    Private Sub Form_KeyPress(Enter As Integer)
    Beep
    End Sub

    But when I press enter, nothing happens. How would I get it to work. Also, how would I use the arrow buttons?
    Thanks.

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Did you change Form's KeyPreview to True?
    HTH

    ------------------
    Visual Basic Programmer
    ------------------
    PolComSoft
    You will hear a lot about it.


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    New Jersey
    Posts
    334

    Post

    Ok, thanks a lot! It works now. What does changing the value of KeyPreview do? Thanks.

  4. #4
    Guest

    Post

    You could also use KeyAscii instead of KeyCode

  5. #5
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    Makes the Key events (Keypress, KeyUp and KeyDown) go to the form instead of to any control.

    [This message has been edited by Juan Carlos Rey (edited 01-22-2000).]

  6. #6
    Guest

    Post

    i think you'll find it is supposed to be (keyascii as integer) instead of enter. thy that first.

    if you need the arrow keys:
    Code:
    form1_keydown(Keycode as Integer, shift as integer)
    if keycode = vbkeyLeft then 'do stuff for left arrow
    etc...

    [This message has been edited by wossname (edited 01-22-2000).]

  7. #7
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    Or use the ASC reference;
    A=65
    B=66
    so:
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 65 Then MsgBox "A"
    If KeyCode = 66 Then MsgBox "B"
    End Sub
    NOTE: It ignores 'case' A or a B or B either activate the code!

    ------------------
    DiGiTaIErRoR

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    New Jersey
    Posts
    334

    Post

    Thanks both of you, but it still doesn't work. I tried both ways, but nothing happens when I press the buttons. I also tried the same with the KeyPress function.
    Thanks for the help.

    ------------------
    Regards,
    Alexander McAndrew
    VB Zone
    http://gsenterprise.server101.com


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