home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95 / keystuff.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  2KB  |  57 lines

  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4. int
  5. main( int argc, char * argv[] )
  6. {
  7.     INPUT_RECORD k ;
  8.     KEY_EVENT_RECORD * pKey=&k.Event.KeyEvent;
  9.     DWORD count = 0;
  10.     int rc=0, c, i ;
  11.     HWND hWin = NULL;
  12.     HANDLE hKbd = NULL; 
  13.     char title[128];
  14.  
  15.     if ( argc >= 2 ) {
  16.         sprintf(title,"%s - K-95",argv[1]);
  17.     }
  18.     else
  19.         strcpy(title,"K-95");
  20.     hWin = FindWindow(NULL, title);
  21.  
  22.     if ( !hWin ) {
  23.         printf("Unable to find window handle\n");
  24.         return(1);
  25.     }
  26.         
  27.     hKbd = GetStdHandle( STD_INPUT_HANDLE ) ;
  28.  
  29.     while ( 1 ) {
  30.         if ( WAIT_OBJECT_0 == WaitForSingleObject(hKbd,-1) ) {
  31.             rc = ReadConsoleInput( hKbd, &k, 1, &count ) ;
  32.         }
  33.         if ( count && 
  34.              k.EventType == KEY_EVENT &&
  35.              pKey->bKeyDown) {
  36.             PostMessage(hWin,
  37.                          WM_KEYDOWN,
  38.                          pKey->wVirtualKeyCode,
  39.                          (pKey->dwControlKeyState & ENHANCED_KEY?1:0)<<24 |
  40.                          pKey->wVirtualScanCode << 16 | 
  41.                          1
  42.                          );
  43.             PostMessage(hWin,
  44.                          WM_KEYUP,
  45.                          pKey->wVirtualKeyCode,
  46.                          1 << 31 |
  47.                          1 << 30 |
  48.                          (pKey->dwControlKeyState & ENHANCED_KEY?1:0)<<24 |
  49.                          pKey->wVirtualScanCode << 16 | 
  50.                          1
  51.                          );
  52.         }
  53.     }
  54.  
  55.     return(0);
  56. }
  57.