Key press event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LTCCTL
    New Member
    • Feb 2008
    • 49

    Key press event

    Hi All,

    I am trying to use the key combination to perform a specific task, at present I have developed a windows mobile/smartphone application using the key 5, when I press key 5 it gives me some stored information into the textboxes.

    I want to use the key combination # and 5 to get the information into the textboxes.

    please, suggest me the way to do it.

    Thanks in advance

    LTCCTL
  • markmcgookin
    Recognized Expert Contributor
    • Dec 2006
    • 648

    #2
    Originally posted by LTCCTL
    Hi All,

    I am trying to use the key combination to perform a specific task, at present I have developed a windows mobile/smartphone application using the key 5, when I press key 5 it gives me some stored information into the textboxes.

    I want to use the key combination # and 5 to get the information into the textboxes.

    please, suggest me the way to do it.

    Thanks in advance

    LTCCTL
    I would put the event handler for 5 in the onPress event for # .... and remove it once they have stopped pressing # ... so the event for 5 is only going to be caught when the # key is down.... would that help?

    Comment

    • LTCCTL
      New Member
      • Feb 2008
      • 49

      #3
      Originally posted by markmcgookin
      I would put the event handler for 5 in the onPress event for # .... and remove it once they have stopped pressing # ... so the event for 5 is only going to be caught when the # key is down.... would that help?

      Thanks for suggesting me the way to do it.

      I have used the key down event and tried to use the if condition to catch both the key press events, but it is giving me error, may be I am doing it wrong.

      could you please let me know, how exactly it works?

      Thanks and Regards
      LTCCTL

      Comment

      • markmcgookin
        Recognized Expert Contributor
        • Dec 2006
        • 648

        #4
        Originally posted by LTCCTL
        Thanks for suggesting me the way to do it.

        I have used the key down event and tried to use the if condition to catch both the key press events, but it is giving me error, may be I am doing it wrong.

        could you please let me know, how exactly it works?

        Thanks and Regards
        LTCCTL
        Can you post the error please?

        Comment

        • LTCCTL
          New Member
          • Feb 2008
          • 49

          #5
          Originally posted by markmcgookin
          Can you post the error please?

          Hi,

          I have taken 2 boolean variables, in the key down events of # and 5, it will be set to true and if both of them are true then the information will be shown in the textboxes.

          Now the problem is whenever I press # or 5, the information is shown in the textboxes.

          I am using I-mate, in that to get access to # and 5 we have to press the shift key, when I press shift key then keydown event of shift is fired.

          Should I take another variable to store the shift keydown event?

          the code is given below:

          public bool kp, kp1;

          private void Form1_KeyDown(o bject sender, KeyEventArgs e)
          {
          if ((e.KeyCode == System.Windows. Forms.Keys.D5))
          {
          kp = true; //5
          }
          else
          {
          kp = false;
          }
          if ((e.KeyCode == System.Windows. Forms.Keys.F9))
          {
          kp1 = true; //#
          }
          else
          {
          if (kp1!=true )
          {
          kp1 = false;
          }
          }
          if (kp1 == true)
          {
          if (kp == true)
          {
          label1.Text = "# & 5 keys are pressed";
          }
          }
          }

          please let me know what mistake I am making

          Comment

          • LTCCTL
            New Member
            • Feb 2008
            • 49

            #6
            Originally posted by markmcgookin
            Can you post the error please?

            Hi,

            I have taken 2 boolean variables, in the key down events of # and 5, it will be set to true and if both of them are true then the information will be shown in the textboxes.

            Now the problem is whenever I press # or 5, the information is shown in the textboxes.

            I am using I-mate, in that to get access to # and 5 we have to press the shift key, when I press shift key then keydown event of shift is fired.

            Should I take another variable to store the shift keydown event?

            the code is given below:

            public bool kp, kp1;

            private void Form1_KeyDown(o bject sender, KeyEventArgs e)
            {
            if ((e.KeyCode == System.Windows. Forms.Keys.D5))
            {
            kp = true; //5
            }
            else
            {
            kp = false;
            }
            if ((e.KeyCode == System.Windows. Forms.Keys.F9))
            {
            kp1 = true; //#
            }
            else
            {
            if (kp1!=true )
            {
            kp1 = false;
            }
            }
            if (kp1 == true)
            {
            if (kp == true)
            {
            label1.Text = "# & 5 keys are pressed";
            }
            }
            }

            please let me know what mistake I am making

            Thanks & Regards
            LTCCTL

            Comment

            • markmcgookin
              Recognized Expert Contributor
              • Dec 2006
              • 648

              #7
              Originally posted by LTCCTL
              Hi,

              I have taken 2 boolean variables, in the key down events of # and 5, it will be set to true and if both of them are true then the information will be shown in the textboxes.

              Now the problem is whenever I press # or 5, the information is shown in the textboxes.

              I am using I-mate, in that to get access to # and 5 we have to press the shift key, when I press shift key then keydown event of shift is fired.

              Should I take another variable to store the shift keydown event?

              the code is given below:

              public bool kp, kp1;

              private void Form1_KeyDown(o bject sender, KeyEventArgs e)
              {
              if ((e.KeyCode == System.Windows. Forms.Keys.D5))
              {
              kp = true; //5
              }
              else
              {
              kp = false;
              }
              if ((e.KeyCode == System.Windows. Forms.Keys.F9))
              {
              kp1 = true; //#
              }
              else
              {
              if (kp1!=true )
              {
              kp1 = false;
              }
              }
              if (kp1 == true)
              {
              if (kp == true)
              {
              label1.Text = "# & 5 keys are pressed";
              }
              }
              }

              please let me know what mistake I am making

              Thanks & Regards
              LTCCTL
              Are you developing this in Visual Studio? Have you tried using breakpoints during debug mode to find out some more about what events are being fired and when?

              Mark

              Comment

              • LTCCTL
                New Member
                • Feb 2008
                • 49

                #8
                Originally posted by markmcgookin
                Are you developing this in Visual Studio? Have you tried using breakpoints during debug mode to find out some more about what events are being fired and when?

                Mark

                Hi Mark,

                Thanks for your help and suggestions I have done it.

                Regards
                LTCCTL

                Comment

                Working...