home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / CHAP6.ZIP / KBDEVENT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.9 KB  |  88 lines

  1. /*
  2.     KBDEVENT.C -- Generates system wide keyboard events
  3.  
  4.     From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
  5.     by Andrew Schulman, Dave Maxey and Matt Pietrek
  6.  
  7.     Build using: WINIOBC KBDEVENT (for Borland C++ v3.00)
  8.                  WINIOMS KBDEVENT (for Microsoft C/SDK)
  9. */
  10.  
  11. #include <windows.h> 
  12. #include "winio.h" 
  13. #ifdef __BORLANDC__
  14. #define _asm asm
  15. #endif
  16.  
  17.  
  18. HANDLE hTimer;
  19.  
  20. #define KE_RELEASE 0x8000
  21.  
  22. /* undocumented function */ 
  23. void (FAR PASCAL *Keybd_Event)(void);
  24.  
  25. FARPROC lpfnTimerFunc;
  26.  
  27. #include "checkord.c"
  28.  
  29. BOOL StopCycling(HWND hwnd)
  30.     {
  31.     FreeProcInstance(lpfnTimerFunc);
  32.     KillTimer(winio_current(), hTimer);
  33.     return TRUE;
  34.     }
  35.  
  36. WORD FAR PASCAL TimerFunc(HWND hwnd, WORD wMsg, int id, DWORD dwTime)
  37.     {
  38.     _asm mov ax, VK_MENU; 
  39.     _asm xor bx, bx;
  40.     Keybd_Event();
  41.     _asm mov ax, VK_TAB;
  42.     _asm xor bx, bx;
  43.     Keybd_Event();
  44.     _asm mov ax, VK_TAB + KE_RELEASE;
  45.     _asm xor bx, bx;
  46.     Keybd_Event();
  47.     _asm mov ax, VK_TAB;
  48.     _asm xor bx, bx;
  49.     Keybd_Event();
  50.     _asm mov ax, VK_TAB + KE_RELEASE;
  51.     _asm xor bx, bx;
  52.     Keybd_Event();
  53.     _asm mov ax, VK_MENU + KE_RELEASE;
  54.     _asm xor bx, bx;
  55.     Keybd_Event();
  56.     
  57.     return 1;
  58.     }
  59.  
  60. int main() 
  61.     {
  62.     // Get Keybd_Event address
  63.     if (! ((FARPROC) Keybd_Event =
  64.         GetProcAddress(GetModuleHandle("USER"), "Keybd_Event")))
  65.         {
  66.         printf("Could not locate Keydb_Event.");
  67.         return 0;
  68.         }
  69.  
  70.     winio_about("KBDEVENT"
  71.         "\nGenerates Alt-Tab system wide keyboard events"
  72.         "\n\nFrom Chapter 6 of"
  73.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  74.         "\nby Andrew Schulman, David Maxey and Matt Pietrek"
  75.         );
  76.     
  77.     lpfnTimerFunc = MakeProcInstance((FARPROC) TimerFunc, __hInst);
  78.     printf("We will now cycle through the Windows tasks.\n\n");
  79.     
  80.     hTimer = SetTimer(winio_current(), 1, 2000, lpfnTimerFunc);
  81.     
  82.     winio_onclose(winio_current(), (DESTROY_FUNC) StopCycling);
  83.     
  84.     printf("\nClose window to exit.");
  85.  
  86.     return 0;
  87.     }
  88.