Guidance
指路人
g.yi.org
software / rapidq / Examples / Memory Process Thread Message / SendKeys.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'Modified by Guidance (http://citymap.126.com) 2002-12-22

'From:  "Gregg Morrison" <greggmor@b...> Date:  Sat Aug 31, 2002  5:24 am
' the API way to send keys to any window, so here it is:
'-----------------
'Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd _
'As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

     DECLARE SUB keybd_event LIB "user32" ALIAS "keybd_event" (BYVAL bVk AS BYTE, BYVAL bScan _
      AS BYTE, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
' This is cross-application SendKeys

'Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


     CONST KEYEVENTF_KEYUP = &H2 ' Release key
     CONST WM_SETFOCUS = &H7& ' &h0007
     CONST WM_KILLFOCUS = &H8& '&h0008


' set focus to any displayed window using hWnd = WindowHandle
     SendMessage hWnd, WM_SETFOCUS, 0&, 0&


' Send a string of keys with optional keypress delay
' This simulates pressing an releasing each key in the Byte Array
'bytKetStack()

     SUB SendKeysAPI(bytKeystack() AS BYTE, _ 'Optional
       DelayMS AS LONG)' = 0)
      DIM nKeyCnt AS LONG

      FOR nKeyCnt = LBOUND(bytKeystack) TO UBOUND(bytKeystack)
       keybd_event bytKeystack(nKeyCnt), 0, 0, 0 ' Simulate KeyPress
       DOEVENTS
' let Windows Process Message
       IF DelayMS THEN SLEEP DelayMS ' Delay - 0, 5, 10 milliseconds if needed

' Simulate KeyRelease
       keybd_event bytKeystack(nKeyCnt), 0, KEYEVENTF_KEYUP, 0
       DOEVENTS
' Let Windows Process Message
      NEXT nKeyCnt

     END SUB


' Here is an example using control keys
     DEFBYTE vbKeyControl = 17 ' CTRL key
     DEFBYTE vbKeyEscape = 27 ' ESC key

     SUB ShowStartMenu()

' Press the Ctrl-Esc key - Same as the 'Windows' key
      keybd_event vbKeyControl, 0, 0, 0
      keybd_event vbKeyEscape, 0, 0, 0
      DOEVENTS

' Release the two keys
      keybd_event vbKeyControl, 0, KEYEVENTF_KEYUP, 0
      keybd_event vbKeyEscape, 0, KEYEVENTF_KEYUP, 0
      DOEVENTS

     END SUB
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Tue 2024-12-10  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2003-07-14 16:31:11