Results 1 to 8 of 8

Thread: Enter

  1. #1
    hasandak
    Guest

    Question

    How can I make the Enter key to act like tab
    so the user will be able to navigate
    with the tab and also with the Enter key?

  2. #2
    Guest
    Put this in the Form_KeyPress event or any KeyPress event.


    Code:
        If KeyAscii = vbKeyReturn Then SendKeys "{TAB}"

  3. #3
    Member
    Join Date
    Jan 2001
    Location
    I thought you knew!!
    Posts
    38

    Wink Or this way...not much difference tho

    Private Sub TheTHINGY#_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 then SendKeys "{tab}"
    End Sub

  4. #4
    Guest

    Re: Or this way...not much difference tho

    Originally posted by PunK
    Private Sub TheTHINGY#_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 then SendKeys "{tab}"
    End Sub

    Exactly the same, 13 is the key code constant for vbKeyReturn. Best to use the constants instead of the key numbers.

  5. #5
    Guest
    It's not "best to use them" really, rather it's a matter of preference. Although it makes code somewhat unproper to some, I tend to use numbers more than constants.

  6. #6
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    as do i.
    Although in that case you get lucky because vbkeyreturn is the scancode number, not the ascii number. They just happen to be the same for the enter button.
    perhaps this code will work slightly better:

    Private Sub DestTextBox_KeyDown(KeyCode As Integer, Shift As Integer)
    if keycode = vbkeyenter then keycode = vbkeytab
    end sub

    It actually convinces the program that you pressed the tab instead of the enter key. The other samples said you pressed it in addition to the enter key.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  7. #7
    Frenzied Member zuperman's Avatar
    Join Date
    Dec 2000
    Location
    Portugal
    Posts
    1,033
    just a correction:

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Then
    KeyAscii = 0
    SendKeys "{TAB}"
    End If
    End Sub

    keyascii=0
    this way it disables that annoying beep when u hit the enter key
    Help keep this forum clean: Remember to mark your thread as resolved · Search before you post · Remember to rate posts that help

    VS2010: Visual Studio 2010 Keybinding Posters
    · Service Pack 1
    Tools: GhostDoc - automatically generates XML documentation comments
    · NuGet package Manager · PowerCommands IDE extensions
    Source Control: ankhsvn - integration for SVN
    · Windows Shell Extension for Subversion

    Development Laptop: Intel Core i5 430M 2.26 GHz @ 2.53 GHz
    · 4096 MB, DDR3 PC3-8500F (533 MHz), Kingston · ATI Mobility Radeon HD 5470 · 15.6 @ 16:9, 1366x768 pixel, HD LED LCD

    I follow:
    JoelOnSoftware - A weblog by Joel Spolsky, a programmer working in New York City, about software and software companies
    ScottGu's Blog - Scott Guthrie works for Microsoft as the Product Manager of the .NET Framework
    Portugal-a-Programar - Portuguese Developers Community
    .NET Rocks! - is a weekly Internet audio talk show for .NET Developers.

    Programming Languages:
    C#
    · VB.NET · JAVA · PHP · Javascript
    Other:
    XML
    · HTML · CSS · JQuery · SQL



    *** Proudly Portuguese ***

  8. #8
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    hmm. i had an error in mine anyway.
    I named a constant wrong, and it doesn't work with text boxes.
    vbkeyreturn should have been vbkeyenter (to start with).

    None of the other codes caused a beep.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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