Results 1 to 10 of 10

Thread: Certain Keys Pressed??

Hybrid View

  1. #1
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Certain Keys Pressed??

    Set the KeyPreview property of your Form to true. Then test for the desired keys in the Form_KeyDown or KeyUp event.
    "It's cold gin time again ..."

    Check out my website here.

  2. #2

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Re: Certain Keys Pressed??

    i still dont get what code is involved etc...

    Thx anyway
    Nothing is Impossible you say?......Try slamming a revolving door!

  3. #3

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Re: Certain Keys Pressed??

    ok i have fidled around with that and iv got

    VB Code:
    1. KeyCode = "5"
    2. msgbox "Wee"

    as i guessed since keycode is integer but hwo would you do the above with letters?
    Nothing is Impossible you say?......Try slamming a revolving door!

  4. #4
    Lively Member
    Join Date
    Mar 2005
    Location
    Scotland
    Posts
    123

    Re: Certain Keys Pressed??

    Dont know if this will help

    It doesnt work with letter but it will work with numbers

    VB Code:
    1. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    2. KeyCode = "k"
    3. MsgBox "maw"
    4. End Sub

    There u go

  5. #5
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Certain Keys Pressed??

    Try this:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    4.     If KeyCode = vbKeyK Then
    5.         If Shift And vbCtrlMask > 0 Then
    6.             MsgBox "Ctrl+K was pressed"
    7.         End If
    8.     End If
    9. End Sub
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  6. #6
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: Certain Keys Pressed??

    VB Code:
    1. If KeyCode = vbKeyK Then 'If the "K" key is pressed.
    2.     If Shift and vbCtrlMask Then 'If Control is held down
    3.         Msgbox "Hello"
    4.     EndIf
    5. EndIf

  7. #7
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Certain Keys Pressed??

    Quote Originally Posted by Aaron Smith
    Dont know if this will help

    It doesnt work with letter but it will work with numbers

    VB Code:
    1. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    2. KeyCode = "k"
    3. MsgBox "maw"
    4. End Sub

    There u go
    Won't ever work!! KeyCode is an integer... and you're trying to assign a string value.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  8. #8
    Lively Member harishs's Avatar
    Join Date
    Jul 2005
    Location
    Bombay, India
    Posts
    118

    Thumbs up Re: Certain Keys Pressed??

    try out this 1

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyK And Shift = vbCtrlMask Then
    MsgBox "Got Ctrl + K"
    End If
    End Sub

    Happy Coding
    harry

  9. #9
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: Certain Keys Pressed??

    Quote Originally Posted by harishs
    try out this 1

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyK And Shift = vbCtrlMask Then
    MsgBox "Got Ctrl + K"
    End If
    End Sub

    Happy Coding
    harry
    No, shift might not be equal to vbCtrlMask. It should be Shift And vbCtrlMask > 0.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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