Results 1 to 6 of 6

Thread: Detect Shift + Arrow key in form keydown event in BLANK form

  1. #1

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Unhappy Detect Shift + Arrow key in form keydown event in BLANK form

    Hi guys,

    Due to some weird requirement, I need to detect shift + arrow key in blank form. But it's not working. I also tried overriding IsInputKey method but it only detects single key press (like arrow key) but when multiple key are pressed it simply doesn't work.

    Is there any workaround?
    I am using .NET 2010 with Windows 7

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Detect Shift + Arrow key in form keydown event in BLANK form

    Hi,

    You can try it like this;

    vb Code:
    1. Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    2.         If e.Shift And e.KeyCode = Keys.Up Then
    3.             MsgBox("You pressed Shift and Arrowkey up")
    4.         End If
    5.      
    6.     End Sub
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Detect Shift + Arrow key in form keydown event in BLANK form

    Follow the Blog link in my signature and check out my post on keyboard events.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    New Member
    Join Date
    Mar 2011
    Posts
    10

    Re: Detect Shift + Arrow key in form keydown event in BLANK form


    If e.keycode=keys.right then
    if e.keycode=keys.shift then
    (Code goes here)
    end if
    end if


    I'm writing this from memory, so don't hate on me if it doesn't work.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Detect Shift + Arrow key in form keydown event in BLANK form

    Quote Originally Posted by Exiled View Post

    If e.keycode=keys.right then
    if e.keycode=keys.shift then
    (Code goes here)
    end if
    end if


    I'm writing this from memory, so don't hate on me if it doesn't work.
    It won't work. You've got two nested If statements and they are both testing e.KeyCode but for different values. e.KeyCode can never have two different values at the same time, so the contents of the inner If block can never be executed.

    My blog post explains how to test for key combinations that include specific modifiers.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: Detect Shift + Arrow key in form keydown event in BLANK form

    Hi jmcilhinney,

    Very nice blog regarding key events. But it didn't solved the problem in blank form. Surely, it worked when I dropped textbox in form. Anyway, I solved the issue with IMessageFilter interface. I hope you write blog regarding IMessageFilter someday. It would be very helpful.

    Thanks all for help :-)
    I am using .NET 2010 with Windows 7

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