FILE: xpress.txt FILE SIZE: 7,936 bytes FILE DATE: 09/18/98 UPLOADED BY: Christopher Hargett, HIS Software cwhargett@bigfoot.com AUTHOR: Christopher Hargett TYPE: Public Domain DESCRIPTION: 32 bit PRESS and PRESSKEY replacements for C4. Eh...maybe C5? COMMENTS: Might not work too good with NT. Haven't been there or done that. MS docs say to use SendInput instead of keybd_event for NT. Please let me know if you find a problem. ! 9/18/1998 13:51 by Christopher W. Hargett ============================================== ! ! Required equates !============================================================================= * Splat! == CHAR EQUATE(BYTE) DWORD EQUATE(ULONG) WORD EQUATE(SIGNED) LPCSTR EQUATE(CSTRING) LPSTR EQUATE(CSTRING) CHAR EQUATE(BYTE) VK_SHIFT EQUATE(10h) VK_CONTROL EQUATE(11h) VK_MENU EQUATE(12h) VK_CAPITAL EQUATE(14h) KEYEVENTF_KEYUP EQUATE(2) ! 9/18/1998 13:51 by Christopher W. Hargett ============================================== ! ! Required map entries !============================================================================= * Splat! == map xPress(string aString, Byte ShouldSleep=True) xPressKey(long aCode, byte ShouldSleep=True) module('Win Map') keybd_event(BYTE,BYTE,DWORD,DWORD),PASCAL CharToOemA(*LPCSTR,*LPSTR),BOOL,PASCAL,RAW OemKeyScan(WORD),DWORD,PASCAL OMIT('***',_WIDTH32_) VkKeyScan(WORD),WORD,PASCAL *** COMPILE('***',_WIDTH32_) VkKeyScan(CHAR),SIGNED,PASCAL,NAME('VkKeyScanA') *** MapVirtualKeyA(UNSIGNED,UNSIGNED),UNSIGNED,PASCAL GetQueueStatus(UNSIGNED),DWORD,PASCAL GetKeyState(SIGNED),SIGNED,PASCAL Sleep(DWORD),PASCAL end end xPress PROCEDURE (string aString, Byte ShouldSleep) ! Declare Procedure ! 9/18/1998 8:40 by Christopher W. Hargett ============================================== ! ! aString String to express (British : designated to be delivered without delay ! by special messenger) ! ShouldSleep Give up remaining time slice so the target app can process the messages ! ! I used Static here to reduce overhead (I think). It served no other purpose. !============================================================================= * Splat! == NeedAShift BYTE,STATIC ! Is a Shifted Keystroke needed ndx LONG,STATIC ! Generic index for looping Vk WORD,STATIC ! Contains VirtualKey of aChar Scan DWORD,STATIC ! Scancode of aChar anOemchar CSTRING(2),STATIC ! OEM of aChar aChar CSTRING(2),STATIC ! a character instance of aString CapIsOn BYTE,STATIC ! Is the CAP Key "on" CODE ! Begin processed code LOOP ndx=1 to LEN(aString) BY 1 ! Loop through the string aChar = aString[ndx : ndx] ! Get character at pos ndx CapIsOn = BAND(1b,GetKeyState(VK_CAPITAL)) ! Is Caps Lock on? IF IsAlpha(aChar) ! If the character is alphabetic NeedAShift = CHOOSE(LOWER(aChar)=aChar AND CapIsOn | ! look and see if a shift key OR UPPER(aChar)=aChar AND NOT CapIsOn, True, False) ! is needed. ELSIF INSTRING(aChar,'~!@#$%^&*()_+|{{}:"<<>?',1) ! Look for other keys that may NeedAShift = True ! need a shift key. ELSE ! otherwise NeedAShift = False ! no shift key is needed. END IF NeedAShift THEN ! If a shift key is needed, keybd_event(VK_SHIFT, MapVirtualKeyA(VK_SHIFT, 0), 0, 0) ! press it (and hold) END Vk = BAND(VkKeyScan(VAL(aChar)), 0FFh) ! Get the virtual key code for the char CharToOemA(aChar, anOemchar) ! Get the OEM character code Scan = BAND(OemKeyScan(VAL(anOemchar)), 0FFh) ! Get the scan code keybd_event(Vk, Scan, 0, 0) ! Press the key. keybd_event(Vk, Scan, KEYEVENTF_KEYUP, 0) ! Release the key. IF NeedAShift THEN ! If a shift was needed, keybd_event(VK_SHIFT, MapVirtualKeyA(VK_SHIFT, 0), KEYEVENTF_KEYUP, 0) ! release the shift key. END IF ShouldSleep THEN ! If ShouldSleep Sleep(0) ! give the target app a chance to END ! process the messages. end return xPressKey PROCEDURE (long aCode, byte ShouldSleep) ! Declare Procedure ! 9/18/1998 13:40 by Christopher W. Hargett ============================================== ! ! aCode Clarion Keycode to express ! ShouldSleep Should xPressKey give the target app a chance to process the key. !============================================================================= * Splat! == CODE ! Begin processed code if band(100h,aCode) THEN ! If the shift key is needed, keybd_event(VK_SHIFT, MapVirtualKeyA(VK_SHIFT, 0), 0, 0) ! press and hold the shift key END if band(200h,aCode) THEN ! If the Control key is needed, keybd_event(VK_CONTROL, MapVirtualKeyA(VK_CONTROL, 0), 0, 0) ! press and hold the control key END if band(400h,aCode) THEN ! If the Alt key is needed, keybd_event(VK_MENU, MapVirtualKeyA(VK_MENU, 0), 0, 0) ! press and hold the alt key END keybd_event(BAND(aCode,0FFh), MapVirtualKeyA(BAND(aCode,0FFh), 0), 0, 0) ! Press and release the unshifted, uncontrolled, keybd_event(BAND(aCode,0FFh), MapVirtualKeyA(BAND(aCode,0FFh), 0), KEYEVENTF_KEYUP, 0) ! unalted key if band(100h,aCode) THEN keybd_event(VK_SHIFT, MapVirtualKeyA(VK_SHIFT, 0), KEYEVENTF_KEYUP, 0) ! Release Shift Key if appropriate END if band(200h,aCode) THEN keybd_event(VK_CONTROL, MapVirtualKeyA(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0) ! Release Control key if appropriate END if band(400h,aCode) THEN keybd_event(VK_MENU, MapVirtualKeyA(VK_MENU, 0), KEYEVENTF_KEYUP, 0) ! Release alt key if appropriate END IF ShouldSleep THEN ! If ShouldSleep Sleep(0) ! give the target app a chance to END ! process the messages. return