


De antemano muchas gracias


| |||
Encender/Apagar leds del teclado con o c++ Buen día, apenas estoy iniciando con el lenguaje de C y la tarea que me han encomendado es poder prender y apagar los leds del teclado, estuve leyendo información de como funcionan los teclados y he encontrado codigo que por algun motivo no ha querido funcionar ![]() ![]() ![]() De antemano muchas gracias ![]() ![]() |
| |||
Respuesta: Encender/Apagar leds del teclado con o c++ HOLA :me gustaria que compartieras conmigo esa info sobre los teclados mirandolo deporonto podria ayudarte se algo de c si deseas mandame la info y si tienes codigo mejor chao |
| |||
Respuesta: Encender/Apagar leds del teclado con o c++ Hola, gracia por su ayuda. Bueno buscando un poco mas de informacion en internet encontre un header que se llama keyboard.h y al parecer tiene la funcion para trabajar los leds pero no se como implementarla o hacerla trabajar. No puedo pegar los link para que vean la libreria pero le ponen en google keyboard.c y es el primer link (koders.com) Y sobre el codigo que al parecer funciona es este: /* Gh0st by WarGame. A proggy that flashes the leds of the keyboard - */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <linux/kd.h> #include <sys/types.h> #include <sys/ioctl.h> #include <signal.h> int fd; void die(int signum) { printf("D3ad\n"); ioctl(fd, KDSETLED, 0x0); close(fd); exit(1); } int main(int argc,char *argv[]) { int act = 0xff,interval; if(argv[1] == NULL) { printf("Gh0st by WarGame\n"); printf("Usage: %s <flashing interval in seconds>\n",argv[0]); exit(-1); } interval = atoi(argv[1]); if ((fd = open("/dev/console", O_NOCTTY)) == -1) { perror("open"); exit(-1); } signal(SIGINT,die); signal(SIGTERM,die); signal(SIGQUIT,die); signal(SIGTSTP,die); printf("Gh0st\n"); while(1) { if(act == 0xff) act = 0x07; else act = 0xff; ioctl(fd,KDSETLED,act); sleep(interval); } } Este funciona bajo Linux (yo trabajo en ubuntu) lo que hace al parecer es hacer que el led correspondiente a Bloq Despl parpadee conforme trabaja el procesador o la red (Una de esas dos cosas) pero no estoy seguro y no entiendo como trabaja. Pero necesito prender/apagar los leds bajo windows XP y creo es muy diferente, ya que leyendo por internet hay que hacerlo con la API de windows, escribiendo y leyendo en la direccion de memoria donde se encuentra el teclado o algo asi. Muchas gracias de nuevo por su interes a cesar15 y Anubis_Slash espero y me puedan ayudar soy muy novato en esto de C/C++, pero aprendo rapido. |
| |||
Respuesta: Encender/Apagar leds del teclado con o c++ vale, vale que me he hecho de muchso codigos que no los he hecho funcionar ![]() ![]() ![]() Pero que lo he hecho en VB6 y me ha quedado y buscando en el MSDN encontre el codigo que necesito en C++, pero en los dos casos es ocupando la API de windows (user32) y lo que necesito es interactuar con el teclado directamente mandando los comandos respectivos todo esto en C o C++. Les dejo el codigo de VB, C++ y otro que creo hace lo que necesito pero no lo he hecho funcionar, el ultimo ya entendi el funcionamiento y es lo que necesito pero no lo he hecho funcionar si alguien me ayuda ha hacerlo trabajar y decirme lo que le hace falta estaria muy agradecido. Visual Basic 6:
Código:
en C++' Constantes para las teclas y otros Const KEYEVENTF_KEYUP = &H2 Const KEYEVENTF_EXTENDEDKEY = &H1 Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) Public aBD, aBM, BN Public con1, con2, con3 Sub Pulsar_Tecla(Tecla As Long) Call keybd_event(Tecla, 0, 0, 0) Call keybd_event(Tecla, 0, KEYEVENTF_KEYUP, 0) End Sub Private Sub btnABloqDespl_Click() con3 = con3 + 1 If con3 = 1 Then aBD = True Else aBD = False con3 = 0 End If End Sub Private Sub btnABloqMayus_Click() con2 = con2 + 1 If con2 = 1 Then aBM = True Else aBM = False con2 = 0 End If End Sub Private Sub btnABloqNum_Click() con1 = con1 + 1 If con1 = 1 Then aBN = True Else aBN = False con1 = 0 End If End Sub Private Sub btnBloqDespl_Click() Call Pulsar_Tecla(&H91) End Sub Private Sub btnBloqMayus_Click() Call Pulsar_Tecla(&H14) End Sub Private Sub btnBloqNum_Click() Call Pulsar_Tecla(&H90) End Sub Private Sub Timer1_Timer() If con1 Then Call Pulsar_Tecla(&H90) End If If con2 Then Call Pulsar_Tecla(&H14) End If If con3 Then Call Pulsar_Tecla(&H91) End If End Sub
Código:
#include <cstdlib> #include <iostream> #include <windows.h> using namespace std; void SetNumLock( BOOL bState) { BYTE keyState[256]; GetKeyboardState((LPBYTE)&keyState); if((bState && !(keyState[VK_NUMLOCK] & 1)) || (!bState && (keyState[VK_NUMLOCK] & 1))) { keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0); keybd_event(VK_NUMLOCK, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); } } int main(int argc, char *argv[]) { SetNumLock(TRUE); system("PAUSE"); return EXIT_SUCCESS; } En C
Código:
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <dos.h> #include <conio.h> #define KEYBOARD_INT 9 #define KB_SPECIAL_MASK 0x3F #define KB_CTRL_ALT_FLAG (KB_CTRL_FLAG | KB_ALT_FLAG) int three_finger_flag; int key_led_flag; int (*keyboard_callback)(int key) = NULL; void (*keyboard_lowlevel_callback)(int key) = NULL; /* killough 3/21/98 */ static int keyboard_installed; volatile char key[128]; /* key pressed flags */ volatile int key_shifts = 0; #define KEY_BUFFER_SIZE 256 static volatile int key_buffer[KEY_BUFFER_SIZE]; static volatile int key_buffer_start = 0; static volatile int key_buffer_end = 0; static volatile int key_extended = 0; static volatile int key_pad_seq = 0; static volatile int key_pause_loop = 0; static int (*keypressed_hook)() = NULL; static int (*readkey_hook)() = NULL; static inline int kb_send_data(unsigned char data) { long i; int resends = 4; int temp; do { outportb(0x60, data); i = 2000000L; while (--i) { temp = inportb(0x60); if (temp == 0xFA) return 1; else if (temp == 0xFE) break; } } while ((resends-- > 0) && (i)); return 0; } /* update_leds: * Sets the state of the keyboard LED indicators. */ static inline void update_leds() { if ((!kb_send_data(0xED)) || (!kb_send_data((key_shifts>>8) & 7))) kb_send_data(0xF4); } void set_leds(int leds) { /* killough 3/22/98 */ if (leds < 0) { update_leds(); } else { if ((!kb_send_data(0xED)) || (!kb_send_data((leds>>8)&7))) kb_send_data(0xF4); } /* killough 3/22/98 */ } |