Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. X - Key as a shortcut creates problem when typing.

X - Key as a shortcut creates problem when typing.

Scheduled Pinned Locked Moved Visual Basic
helpquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Atul Kharecha
    wrote on last edited by
    #1

    I have to add one functionality in my Windows application. When user presses X key, it should do some function by calling routine. However when user is typing something on a form(ex. in textbox), this event should not be fired. Currently due to this event handler code, user is unable to type X key becoz it is calling X key routine. Any solution of this problem? Thanks.

    J T 2 Replies Last reply
    0
    • A Atul Kharecha

      I have to add one functionality in my Windows application. When user presses X key, it should do some function by calling routine. However when user is typing something on a form(ex. in textbox), this event should not be fired. Currently due to this event handler code, user is unable to type X key becoz it is calling X key routine. Any solution of this problem? Thanks.

      J Offline
      J Offline
      Jay Royall
      wrote on last edited by
      #2

      Maybe you could set a boolean flag which gets toggled when the user enters/leaves the textboxes on your form. The x key routine would then check the state of the boolean flag which would determine if the event should go ahead or not.

      A 1 Reply Last reply
      0
      • A Atul Kharecha

        I have to add one functionality in my Windows application. When user presses X key, it should do some function by calling routine. However when user is typing something on a form(ex. in textbox), this event should not be fired. Currently due to this event handler code, user is unable to type X key becoz it is calling X key routine. Any solution of this problem? Thanks.

        T Offline
        T Offline
        Tom Deketelaere
        wrote on last edited by
        #3

        Use alt+x ? Other than that in your function (that is called by the event handler on pressing x) check if the current active control is one where the user can type in (textbox, richtextbox,...) This might be off help: form.ActiveControl

        A 1 Reply Last reply
        0
        • J Jay Royall

          Maybe you could set a boolean flag which gets toggled when the user enters/leaves the textboxes on your form. The x key routine would then check the state of the boolean flag which would determine if the event should go ahead or not.

          A Offline
          A Offline
          Atul Kharecha
          wrote on last edited by
          #4

          Thanks Liqz, The situation is there is one main form and depending on menu items selection, it is loading user controls on main form, which comes from multiple solutions. So there are many solutions and lots of user controls are taking part here. I do not want to change all the user controls but I want to change only main form. Thanks.

          J 1 Reply Last reply
          0
          • A Atul Kharecha

            Thanks Liqz, The situation is there is one main form and depending on menu items selection, it is loading user controls on main form, which comes from multiple solutions. So there are many solutions and lots of user controls are taking part here. I do not want to change all the user controls but I want to change only main form. Thanks.

            J Offline
            J Offline
            Jay Royall
            wrote on last edited by
            #5

            Take a look at Tom's post below, it is actually a better solution than mine, I was unaware of the ActiveControl method. Using that method you can get the type of the active control, then if the type of active control is a text box, don't do the x key function.

            1 Reply Last reply
            0
            • T Tom Deketelaere

              Use alt+x ? Other than that in your function (that is called by the event handler on pressing x) check if the current active control is one where the user can type in (textbox, richtextbox,...) This might be off help: form.ActiveControl

              A Offline
              A Offline
              Atul Kharecha
              wrote on last edited by
              #6

              Thanks Tom, I looked for X key combination with Alt key but it is returning me only Alt key and not with combination of other key with Alt so i am unable to trap event for Alt+X key combination. Also I looked on ActiveControl but the deal is I have layers of controls like this: Bottom to top Form User Control Split control User control Textbox and other controls. When I tried to get active control, it returns me "System.Windows.Forms.SplitContainer" and not individual controls. Any help please? Thanks.

              L T 2 Replies Last reply
              0
              • A Atul Kharecha

                Thanks Tom, I looked for X key combination with Alt key but it is returning me only Alt key and not with combination of other key with Alt so i am unable to trap event for Alt+X key combination. Also I looked on ActiveControl but the deal is I have layers of controls like this: Bottom to top Form User Control Split control User control Textbox and other controls. When I tried to get active control, it returns me "System.Windows.Forms.SplitContainer" and not individual controls. Any help please? Thanks.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                Hi, the KeyDown event offers a KeyEventArgs object containing information about the most recent key, but also the current state of the modifier keys such as Alt, Control, Shift. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


                1 Reply Last reply
                0
                • A Atul Kharecha

                  Thanks Tom, I looked for X key combination with Alt key but it is returning me only Alt key and not with combination of other key with Alt so i am unable to trap event for Alt+X key combination. Also I looked on ActiveControl but the deal is I have layers of controls like this: Bottom to top Form User Control Split control User control Textbox and other controls. When I tried to get active control, it returns me "System.Windows.Forms.SplitContainer" and not individual controls. Any help please? Thanks.

                  T Offline
                  T Offline
                  Tom Deketelaere
                  wrote on last edited by
                  #8

                  If the alt+x way is a valid way to go for you I would do it that way, since you have usercontrols the activecontrol will most likly never be to accurate. This code works fine for me:

                  Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
                  If e.Alt = True And e.KeyCode = Keys.X Then
                  MessageBox.Show("success")
                  End If
                  End Sub

                  Property 'Keypreview' from the form set to true If you don't get it working like that I suggest you create a menustrip on the form, add a dummy menu, in the properties of that menu add a shortcut (alt + x), set the property 'visible' from the menustrip to false and do your function in the click event of the menu. (always works that way)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups