can anyone tell me the error in the below attached code..........

actually when 1 press Numpad1 a message telling NumPad1 is pressed, similarly when i press Numpad3 another message telling that NMumpad3 is pressed.......and also when i press both keys ie. Numpad1 & Numpad3 another message telling that "press any one of the key.....

but the code is not working properly............can anyone tell me whats's the problem...............

Recommended Answers

All 4 Replies

anybody please help me.................

you have written the code in form1_keydown event and whenever we press a key the input buffer never takes two inputs at the same time it always takes one by one and when you press numpad1 and numpad3 at the same time it takes input one by one and shows the input which it took earlier and the next time it displays the next pressed key

If you want to to take two inputs at a time like (Alt + F4) you should add code like this

bool altPressed=false;
String keyCode="";
 void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            try
            {
                  if (e.KeyCode == Keys.Alt)
                    altPressed = true;
                
                else
                    keyCode = e.KeyCode.ToString();
               }
           
            catch (Exception ee)
            {
               MessageBox.Show(ee.ToString());
            }                
                  }
        void Form1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (altPressed == true)
                {
                    switch (keyCode)
                    {
                        case "F4": this.Close();
                            break;
                    }
                    e.Handled = true;
                }
altPressed = false;  }

Still not working............when i press alt+f4 simultaneously the message is not coming
can u tell me wat's the problm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.