Results 1 to 10 of 10

Thread: Another stupid Keypress question(RESOLVED)

  1. #1

    Thread Starter
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142

    Talking Another stupid Keypress question(RESOLVED)

    Well, yes, I'm gonna ask a question about the Keypress event. I know it's been beat to death, but I couldnt find my answer with a search so here goes:

    I want the right arrow key to activate the Button click event for a button on my form.

    I have tried many different things with the Keypress and Keydown events, but I cant figure it out. I am currently using this code in the KeyDown event from a thread I saw. It doesent work though.
    VB Code:
    1. If (e.KeyCode = Keys.Right) Then
    2.             Call btnRight_Click(sender, e)
    3.         Else
    4.             e.Handled = False
    5.         End If
    Can anyvody help?
    Last edited by The Phoenix; Sep 1st, 2003 at 02:25 AM.
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Where did you put that code ?
    Attached Files Attached Files

  3. #3

    Thread Starter
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142
    In the KeyDown event for the form.

    I see in your code that it is in the Textbox1 keyDown event. Can you explain that to me? Does that mean that the event will fire only when that textbox has focus? Obviously, I know nothing about this, so any help is greatly appreciated.

    Thanks for the code, BTW.

    <EDIT>
    Well, I tried the code. I didnt have a textbox on my form, so I put one there. I added your code to the textbox1.keydown event. (I hade to change the e.Keycode.Right to e.Keycode = Keys.Right)

    It doesent work. When I press the Right Arrow, it starts cycleing through all my controls.

    I apologize if I'm being dense here. As I said, I don't know much about this kind of thing.
    Last edited by The Phoenix; Aug 31st, 2003 at 02:54 PM.
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    OK . The best bet now is API . It works well . I've got a demo for making hotkeys but it uses ALT+Letter or any else combinations . You wanna have a look ?

  5. #5

    Thread Starter
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142
    Sure. Can't hurt nothing, and I might learn something.

    Thanks!
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

  6. #6
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    Set The Forms KeyPreview Property to true and add this code:

    VB Code:
    1. Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    2.             If (e.KeyCode = Keys.Right) Then
    3.                 Call btnRight_Click(sender, e)
    4.             Else
    5.                 e.Handled = False
    6.             End If
    7. End Sub
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  7. #7

    Thread Starter
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142
    Aha! That works perfectly!

    Thank you very very much! I had gotten it to sort of work on my own, but this is MUCH easier!

    Thanks again!
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Well . I've tried this but if there is a button getting the focus , the form keydown event will not fire . I've trid this before , something like visibling the form if a key is pressed and if the other key is pressed it's shown . I couldn't do this using many ways .I had to use API . That's my point when I mentioned API .

  9. #9
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    Originally posted by Pirate
    Well . I've tried this but if there is a button getting the focus , the form keydown event will not fire . I've trid this before , something like visibling the form if a key is pressed and if the other key is pressed it's shown . I couldn't do this using many ways .I had to use API . That's my point when I mentioned API .
    Even with the forms KeyPreview = True?
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Yes . For making a reliable hotkeys use APIs.

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