dcsimg
Results 1 to 7 of 7

Thread: arrow keys

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2007
    Posts
    259

    arrow keys

    When I use the press key event and the ascii codes for the arrow keys, nothing happens. At first I though it was a problem with the ascii codes I had got, so I made a tiny programme that told you the ascii of all the keys you pressed when you pressed them. It worked for most of them, but not for the arrow keys. I think this is because There is something already happening for the arrow keys. Please can you tell me how to make something happen When I press the arrow keys.
    Thankyou.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: arrow keys

    Use the KeyDown or KeyUp event.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  3. #3
    Hyperactive Member su ki's Avatar
    Join Date
    Oct 2007
    Posts
    354

    Re: arrow keys

    you should use this

    Option Explicit


    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case 37:
    MsgBox "Left"

    Case 38:
    MsgBox "Up"

    Case 39:
    MsgBox "Right"

    Case 40:
    MsgBox "Down"
    End Select
    End Sub

    Private Sub Form_Load()
    Me.KeyPreview = True
    End Sub

  4. #4
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: arrow keys

    Quote Originally Posted by su ki
    Private Sub Form_Load()
    Me.KeyPreview = True
    End Sub
    The is the real important part. You don't necessarily have to do this in code if you don't want to. You can just change this to True on the Form's property page, but, regardless of how you do it, in order for these keys to work, it must be done.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,597

    Re: arrow keys

    Tip: Where su_ki's code uses numbers in the Select Case statement, you can easily us VB constants to make it easier for your, if desired.
    Example: Instead of Case 37 you can use Case vbKeyLeft

  6. #6
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,355

    Re: arrow keys

    Here are a few KeyCode constants:
    Code:
    vbKeyPageUp 	'Page Up Key
    vbKeyPageDown 	'Page Down Key
    vbKeyEnd 	'End Key
    vbKeyHome 	'Home Key
    vbKeyLeft 	'Left Arrow Key
    vbKeyUp		'Up Arrow Key
    vbKeyRight 	'Right Arrow Key
    vbKeyDown 	'Down Arrow Key
    Doctor Ed

  7. #7
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: arrow keys

    f you type "vbKey" and then press Ctrl+Space, you get a dropdown list of all the constants. Here are a whole boat load of them.
    Quote Originally Posted by Ctrl_Space

    vbKeyLButton Left Mouse Button
    vbKeyRButton Right Mouse Button
    vnKeyCancel Cancel Key
    vbKeyMButton Middle Mouse button
    vbKeyBack Back Space Key
    vbKeyTab Tab Key
    vbKeyClear Clear Key
    vbKeyReturn Enter Key
    vbKeyShift Shift Key
    vbKeyControl Ctrl Key
    vbKeyMenu Menu Key
    vbKeyPause Pause Key
    vbKeyCapital Caps Lock Key
    vbKeyEscape Escape Key
    vbKeySpace Spacebar Key
    vbKeyPageUp Page Up Key
    vbKeyPageDown Page Down Key
    vbKeyEnd End Key
    vbKeyHome Home Key
    vbKeyLeft Left Arrow Key
    vbKeyUp Up Arrow Key
    vbKeyRight Right Arrow Key
    vbKeyDown Down Arrow Key
    vbKeySelect Select Key
    vbKeyPrint Print Screen Key
    vbKeyExecute Execute Key
    vbKeySnapshot Snapshot Key
    vbKeyInsert Insert Key
    vbKeyDelete Delete Key
    vbKeyHelp Help Key
    vbKeyNumlock Delete Key

    vbKeyA through vbKeyZ are the key code constants for the alphabet
    vbKey0 through vbKey9 are the key code constants for numbers
    vbKeyF1 through vbKeyF16 are the key code constants for the function keys
    vbKeyNumpad0 through vbKeyNumpad9 are the key code constants for the numeric key pad

    Math signs are:
    vbKeyMultiply - Multiplication Sign (*)
    vbKeyAdd - Addition Sign (+)
    vbKeySubtract - Minus Sign (-)
    vbKeyDecimal - Decimal Point (.)
    vbKeyDivide - Division sign (/)
    vbKeySeparator - Enter (keypad) sign
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width