none
Crear Teclado para Testear teclado fisico RRS feed

  • Pregunta

  • Hola Aficionados 

    Mi problema es el siguiente. Estoy intentando hacer un Test de Teclado con todas la teclas. Utilizo KeyDown para obtener el evento al presionar la tecla el problema es que para que esto me funcione necesito de hacerle click al botón primero antes de presionar la tecla para que me funcione el KeyDown.

    Espero de su ayuda

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Teclado
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
            }
    
            private void btEsc_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Escape)
                {
                    e.Handled = true;
                    btEsc.BackColor = Color.Green;
                }
                
                
            }
    
            private void btF1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F1)
                {
                    e.Handled = true;
                    btF1.BackColor = Color.Green;
                }
            }
    
            private void btA_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.A)
                {
                    e.Handled = true;
                    btA.BackColor = Color.Green;
                }
            }
    
            private void btF2_KeyDown(object sender, KeyEventArgs e)
            {
                if(e.KeyCode == Keys.F2)
                {
                    e.Handled = true;
                    btF2.BackColor = Color.Green;
                }
            }
    
            private void btF3_KeyDown(object sender, KeyEventArgs e)
            {
                if(e.KeyCode == Keys.F3)
                {
                    e.Handled = true;
                    btF3.BackColor = Color.Green;
                }
            }
    
            private void btF4_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F4)
                {
                    e.Handled = true;
                    btF4.BackColor = Color.Green;
                }
            }
    
            private void btF5_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F5)
                {
                    e.Handled = true;
                    btF5.BackColor = Color.Green;
                }
            }
    
            private void btF6_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F6)
                {
                    e.Handled = true;
                    btF6.BackColor = Color.Green;
                }
            }
    
            private void btF7_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F7)
                {
                    e.Handled = true;
                    btF7.BackColor = Color.Green;
                }
            }
    
            private void btF8_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F8)
                {
                    e.Handled = true;
                    btF8.BackColor = Color.Green;
                }
            }
    
            private void btF9_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F9)
                {
                    e.Handled = true;
                    btF9.BackColor = Color.Green;
                }
            }
    
            private void btF10_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F10)
                {
                    e.Handled = true;
                    btF10.BackColor = Color.Green;
                }
            }
    
            private void btF11_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F11)
                {
                    e.Handled = true;
                    btF11.BackColor = Color.Green;
                }
            }
    
            private void btF12_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.F12)
                {
                    e.Handled = true;
                    btF12.BackColor = Color.Green;
                }
            }
    
            private void btImp_KeyDown(object sender, KeyEventArgs e)
            {
    
                if (e.KeyCode == Keys.Snapshot) //revisar   Snapshot    PrintScreen
                {
                    e.Handled = true;
                    btImp.BackColor = Color.Green;
                }
            }
    
            private void btIns_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Insert)
                {
                    e.Handled = true;
                    btIns.BackColor = Color.Green;
                }
            }
    
            private void btSupr_KeyDown(object sender, KeyEventArgs e)
            {
                
                if (e.KeyValue == 46) 
                {
                    e.Handled = true;
                    btSupr.BackColor = Color.Green;
                }
            }
    
            private void btCirculo_KeyDown(object sender, KeyEventArgs e)
            {
               
                if (e.KeyValue == 220) 
                {
                    e.Handled = true;
                    btCirculo.BackColor = Color.Green;
                }
            }
    
            private void btUno_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.D1)
                {
                    e.Handled = true;
                    btUno.BackColor = Color.Green;
                }
            }
    
            private void btDos_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.D2)
                {
                    e.Handled = true;
                    btDos.BackColor = Color.Green;
                }
            }
    
            private void btTres_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.D3)
                {
                    e.Handled = true;
                    btTres.BackColor = Color.Green;
                }
            }
    
            private void btCuatro_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.D4)
                {
                    e.Handled = true;
                    btCuatro.BackColor = Color.Green;
                }
            }
    
            private void btCinco_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.D5)
                {
                    e.Handled = true;
                    btCinco.BackColor = Color.Green;
                }
            }
    
            private void btSeis_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.D6)
                {
                    e.Handled = true;
                    btSeis.BackColor = Color.Green;
                }
            }
    
            private void btSiete_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.D7)
                {
                    e.Handled = true;
                    btSiete.BackColor = Color.Green;
                }
            }
    
            private void btOcho_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.D8)
                {
                    e.Handled = true;
                    btOcho.BackColor = Color.Green;
                }
            }
    
            private void btNueve_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.D9)
                {
                    e.Handled = true;
                    btNueve.BackColor = Color.Green;
                }
            }
    
            private void btCero_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.D0)
                {
                    e.Handled = true;
                    btCero.BackColor = Color.Green;
                }
            }
    
            private void btBak_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Back)
                {
                    e.Handled = true;
                    btBak.BackColor = Color.Green;
                }
            }
    
            private void btInicio_KeyDown(object sender, KeyEventArgs e)
            {
                
                if (e.KeyValue == 36) 
                {
                    e.Handled = true;
                    btInicio.BackColor = Color.Green;
                }
            }
    
            private void btSimple_KeyDown(object sender, KeyEventArgs e)
            {
                
                if (e.KeyValue == 219)
                {
                    e.Handled = true;
                    btSimple.BackColor = Color.Green;
                }
            }
    
            private void btAdmiracion_KeyDown(object sender, KeyEventArgs e)
            {
                //MessageBox.Show(e.KeyValue.ToString());
                if (e.KeyValue == 221)
                {
                    e.Handled = true;
                    btAdmiracion.BackColor = Color.Green;
                }
            }
    
            private void btTab_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Tab)
                {
                    e.Handled = true;
                    btTab.BackColor = Color.Green;
                }
            }
    
            private void btQ_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Q)
                {
                    e.Handled = true;
                    btQ.BackColor = Color.Green;
                }
            }
    
            private void btW_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.W)
                {
                    e.Handled = true;
                    btW.BackColor = Color.Green;
                }
            }
    
            private void btE_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.E)
                {
                    e.Handled = true;
                    btE.BackColor = Color.Green;
                }
            }
    
            private void btR_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.R)
                {
                    e.Handled = true;
                    btR.BackColor = Color.Green;
                }
            }
    
            private void btT_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.T)
                {
                    e.Handled = true;
                    btT.BackColor = Color.Green;
                }
            }
    
            private void btY_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Y)
                {
                    e.Handled = true;
                    btY.BackColor = Color.Green;
                }
            }
    
            private void btU_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.U)
                {
                    e.Handled = true;
                    btU.BackColor = Color.Green;
                }
            }
    
            private void btI_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.I)
                {
                    e.Handled = true;
                    btI.BackColor = Color.Green;
                }
            }
    
            private void btO_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.O)
                {
                    e.Handled = true;
                    btO.BackColor = Color.Green;
                }
            }
    
            private void btP_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.P)
                {
                    e.Handled = true;
                    btP.BackColor = Color.Green;
                }
            }
    
            private void btAcento_KeyDown(object sender, KeyEventArgs e)
            {
                //MessageBox.Show(e.KeyValue.ToString());
                if (e.KeyValue == 186)
                {
                    e.Handled = true;
                    btAcento.BackColor = Color.Green;
                }
            }
    
            private void btMas_KeyDown(object sender, KeyEventArgs e)
            {
                //MessageBox.Show(e.KeyValue.ToString());
                if (e.KeyValue == 187)
                {
                    e.Handled = true;
                    btMas.BackColor = Color.Green;
                }
            }
    
            private void btEnter_KeyDown(object sender, KeyEventArgs e)
            {
                MessageBox.Show(e.KeyValue.ToString());
                if (e.KeyCode == Keys.Enter)
                {
                    e.Handled = true;
                    btEnter.BackColor = Color.Green;
                }
            }
    
            private void btEnterbis_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    e.Handled = true;
                    btEnterbis.BackColor = Color.Green;
                }
            }
    
            private void btRePag_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.PageUp)
                {
                    e.Handled = true;
                    btRePag.BackColor = Color.Green;
                }
            }
    
            private void btAvPag_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.PageDown)
                {
                    e.Handled = true;
                    btAvPag.BackColor = Color.Green;
                }
            }
    
            private void btCierreCorchetes_KeyDown(object sender, KeyEventArgs e)
            {
                //MessageBox.Show(e.KeyValue.ToString());
                if (e.KeyValue == 191)
                {
                    e.Handled = true;
                    btCierreCorchetes.BackColor = Color.Green;
                }
            }
    
            private void btAbrecorchetes_KeyDown(object sender, KeyEventArgs e)
            {
                //MessageBox.Show(e.KeyValue.ToString());
                if (e.KeyValue == 222)
                {
                    e.Handled = true;
                    btCierreCorchetes.BackColor = Color.Green;
                }
            }
        
    
        }
    }



    viernes, 15 de abril de 2016 15:32

Respuestas

Todas las respuestas