home *** CD-ROM | disk | FTP | other *** search
- /*
- KBDEVENT.C -- Generates system wide keyboard events
-
- From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
- by Andrew Schulman, Dave Maxey and Matt Pietrek
-
- Build using: WINIOBC KBDEVENT (for Borland C++ v3.00)
- WINIOMS KBDEVENT (for Microsoft C/SDK)
- */
-
- #include <windows.h>
- #include "winio.h"
- #ifdef __BORLANDC__
- #define _asm asm
- #endif
-
-
- HANDLE hTimer;
-
- #define KE_RELEASE 0x8000
-
- /* undocumented function */
- void (FAR PASCAL *Keybd_Event)(void);
-
- FARPROC lpfnTimerFunc;
-
- #include "checkord.c"
-
- BOOL StopCycling(HWND hwnd)
- {
- FreeProcInstance(lpfnTimerFunc);
- KillTimer(winio_current(), hTimer);
- return TRUE;
- }
-
- WORD FAR PASCAL TimerFunc(HWND hwnd, WORD wMsg, int id, DWORD dwTime)
- {
- _asm mov ax, VK_MENU;
- _asm xor bx, bx;
- Keybd_Event();
- _asm mov ax, VK_TAB;
- _asm xor bx, bx;
- Keybd_Event();
- _asm mov ax, VK_TAB + KE_RELEASE;
- _asm xor bx, bx;
- Keybd_Event();
- _asm mov ax, VK_TAB;
- _asm xor bx, bx;
- Keybd_Event();
- _asm mov ax, VK_TAB + KE_RELEASE;
- _asm xor bx, bx;
- Keybd_Event();
- _asm mov ax, VK_MENU + KE_RELEASE;
- _asm xor bx, bx;
- Keybd_Event();
-
- return 1;
- }
-
- int main()
- {
- // Get Keybd_Event address
- if (! ((FARPROC) Keybd_Event =
- GetProcAddress(GetModuleHandle("USER"), "Keybd_Event")))
- {
- printf("Could not locate Keydb_Event.");
- return 0;
- }
-
- winio_about("KBDEVENT"
- "\nGenerates Alt-Tab system wide keyboard events"
- "\n\nFrom Chapter 6 of"
- "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
- "\nby Andrew Schulman, David Maxey and Matt Pietrek"
- );
-
- lpfnTimerFunc = MakeProcInstance((FARPROC) TimerFunc, __hInst);
- printf("We will now cycle through the Windows tasks.\n\n");
-
- hTimer = SetTimer(winio_current(), 1, 2000, lpfnTimerFunc);
-
- winio_onclose(winio_current(), (DESTROY_FUNC) StopCycling);
-
- printf("\nClose window to exit.");
-
- return 0;
- }
-