Pregunta: | 53547 - ACTIVAR UN BOTON POR MEDIO DE PROGRAMACION |
Autor: | gonzalo vargas |
hola amigos bueno quisera saber como por medio de programacion puedo activar una tecla de mi keyboard sin nesecidad de apretarla como por ejemplo la tecla de que activa y desactiva las mayuculas(bloq mayus.)gracias de antemano espeor que puedan ayudarme |
Respuesta: | eider mauricio aristizabal erazo |
///utiliza las librerias:
using System.Runtime.InteropServices; ///Importa estas dll [DllImport("user32.dll")] public static extern int GetKeyState(byte nVirtKey); [DllImport("user32.dll")] static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo); ///Coloca estas variables codificadas Ver tabla ASCII byte NUMLOCK_KEY = 0X90; byte CAPS_KEY = 0x14; ///utiliza estas funciones: private bool KeyStatus(byte KeyCode) { return (GetKeyState(KeyCode) == 1); } private void PresionarTecla(byte KeyCode) { const int EXTENDIDO = 0x1; const int PRESIONAR = 0x2; keybd_event(KeyCode, 0x45, EXTENDIDO, (UIntPtr)0); keybd_event(KeyCode, 0x45, EXTENDIDO | PRESIONAR, (UIntPtr)0); } //EJEMPLO private void button1_Click(object sender, EventArgs e) { if (KeyStatus(CAPS_KEY) == true) MessageBox.Show("Estado Activo"); else MessageBox.Show("Estado Inactivo"); PresionarTecla(NUMLOCK_KEY); } ///Saludos espero te sirva |