home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / keystuff.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  2KB  |  66 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.  
  16.     if ( argc >= 2 ) {
  17.         sprintf(title,"%s - K-95",argv[1]);
  18.     }
  19.     else
  20.         strcpy(title,"K-95");
  21.     hWin = FindWindow(NULL, title);
  22.  
  23.     if ( !hWin ) {
  24.         printf("Unable to find window handle\n");
  25.         return(1);
  26.     }
  27.  
  28.     printf("Window Handle = 0x%x\n",hWin);
  29.         
  30.     hKbd = GetStdHandle( STD_INPUT_HANDLE ) ;
  31.  
  32.     while ( 1 ) {
  33.         if ( WAIT_OBJECT_0 == WaitForSingleObject(hKbd,-1) ) {
  34.             rc = ReadConsoleInput( hKbd, &k, 1, &count ) ;
  35.         }
  36.         if ( count && 
  37.              k.EventType == KEY_EVENT &&
  38.              pKey->bKeyDown) {
  39.             rc = PostMessage(hWin,
  40.                          WM_KEYDOWN,
  41.                          pKey->wVirtualKeyCode,
  42.                          (pKey->dwControlKeyState & ENHANCED_KEY?1:0)<<24 |
  43.                          pKey->wVirtualScanCode << 16 | 
  44.                          1
  45.                          );
  46.             if ( !rc )
  47.                 printf("%c down error=%d\n",GetLastError());
  48.  
  49.               rc = PostMessage(hWin,
  50.                          WM_KEYUP,
  51.                          pKey->wVirtualKeyCode,
  52.                          1 << 31 |
  53.                          1 << 30 |
  54.                          (pKey->dwControlKeyState & ENHANCED_KEY?1:0)<<24 |
  55.                          pKey->wVirtualScanCode << 16 | 
  56.                          1
  57.                          );
  58.             if ( !rc )
  59.                 printf("%c up error=%d\n",GetLastError());
  60.  
  61.         }
  62.     }
  63.  
  64.     return(0);
  65. }
  66.