Guidance
指路人
g.yi.org
software / rapidq / Examples / Devices / keyboard / vbkeyboard.bas

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

  
''  --------------------------------------------------------
''  Form Code By Dusp2000
''         The Internet Doctor
''
''  Keyboard Simulation Using API's

     Private SUB Command1_Click()
     PressKeyVK keyControl, True      ' HOLD DOWN
     PressKeyVK keyAlt, True          ' HOLD DOWN
     PressKeyVK keyF1
     PressKeyVK keyControl, , True    ' RELEASE
     PressKeyVK keyAlt, , True        ' RELEASE
     END SUB

     Private SUB Command2_Click()
     PressKeyVK keyControl, True      ' HOLD DOWN
     PressKeyVK keyEscape
     PressKeyVK keyControl, , True    ' RELEASE
     END SUB

     Private SUB Command3_Click()
     PressKeyVK keyCapsLock
     END SUB

     Private SUB Command4_KeyDown(KeyCode AS INTEGER, Shift AS INTEGER)
     IF KeyCode = 32 THEN Command4_MouseDown 0, 0, 0, 0
     END SUB

     Private SUB Command4_KeyUp(KeyCode AS INTEGER, Shift AS INTEGER)
     IF KeyCode = 32 THEN Command4_MouseUp 0, 0, 0, 0
     END SUB

     Private SUB Command4_MouseDown(Button AS INTEGER, Shift AS INTEGER, X AS SINGLE, Y AS SINGLE)
     PressKeyVK keyAlt, True    ' This activates the TabWindow
     PressKeyVK keyTab
     END SUB

     Private SUB Command4_MouseUp(Button AS INTEGER, Shift AS INTEGER, X AS SINGLE, Y AS SINGLE)
     PressKeyVK keyTab          ' This selectes the next App in the list
     PressKeyVK keyAlt, , True
     END SUB

     Private SUB Command5_Click()
     PressKeyVK keyScrollLock
     END SUB

'' ---------------------------------------------------------
''  Module Code By Dusp2000
''         The Internet Doctor
''
''  Keyboard Simulation Using API's

     DECLARE FUNCTION MapVirtualKey LIB "user32" ALIAS _
      "MapVirtualKeyA" (BYVAL wCode AS LONG, _
      BYVAL wMapType AS LONG) AS LONG
     DECLARE FUNCTION VkKeyScan LIB "user32" ALIAS "VkKeyScanA" (BYVAL _
      cChar AS BYTE) AS INTEGER
     DECLARE SUB keybd_event LIB "user32" (BYVAL bVk AS BYTE, BYVAL _
      bScan AS BYTE, BYVAL dwFlags AS LONG, BYVAL dwExtraInfo AS LONG)
     DECLARE SUB SLEEP LIB "kernel32" (BYVAL dwMilliseconds AS LONG)
     DECLARE FUNCTION GetKeyState LIB "user32" (BYVAL nVirtKey AS _
      LONG) AS INTEGER

     Private CONST KEYEVENTF_EXTENDEDKEY = &H1
     Private CONST KEYEVENTF_KEYUP = &H2

     Public ENUM enumKeys
     keyBackspace = &H8
     keyTab = &H9
     keyReturn = &HD
     keyShift = &H10
     keyControl = &H11
     keyAlt = &H12
     keyPause = &H13
     keyEscape = &H1B
     keySpace = &H20
     keyEnd = &H23
     keyHome = &H24
     keyLeft = &H25
     KeyUp = &H26
     keyRight = &H27
     KeyDown = &H28
     keyInsert = &H2D
     keyDelete = &H2E
     keyF1 = &H70
     keyF2 = &H71
     keyF3 = &H72
     keyF4 = &H73
     keyF5 = &H74
     keyF6 = &H75
     keyF7 = &H76
     keyF8 = &H77
     keyF9 = &H78
     keyF10 = &H79
     keyF11 = &H7A
     keyF12 = &H7B
     keyNumLock = &H90
     keyScrollLock = &H91
     keyCapsLock = &H14
     END ENUM

'Presses the single key represented by sKey
     Public SUB PressKey(sKey AS STRING, Optional bHold AS Boolean, _
      Optional bRelease AS Boolean)

     DIM nVK AS LONG
     nVK = VkKeyScan(ASC(sKey))
     IF nVK = 0 THEN EXIT SUB

     DIM nScan AS LONG
     DIM nExtended AS LONG
     DIM bShift AS Boolean
     DIM bCtrl AS Boolean
     DIM bAlt AS Boolean

     nScan = MapVirtualKey(nVK, 2)
     IF nScan = 0 THEN nExtended = KEYEVENTF_EXTENDEDKEY ELSE nExtended = 0
     nScan = MapVirtualKey(nVK, 0)

     bShift = (nVK AND &H100)
     bCtrl = (nVK AND &H200)
     bAlt = (nVK AND &H400)
     nVK = (nVK AND &HFF)

     IF NOT bRelease THEN
      IF bShift THEN keybd_event enumKeys.keyShift, 0, 0, 0
      IF bCtrl THEN keybd_event enumKeys.keyControl, 0, 0, 0
      IF bAlt THEN keybd_event enumKeys.keyAlt, 0, 0, 0
      keybd_event nVK, nScan, nExtended, 0
     END IF

     IF NOT bHold THEN
      keybd_event nVK, nScan, KEYEVENTF_KEYUP OR nExtended, 0
      IF bShift THEN keybd_event enumKeys.keyShift, 0, KEYEVENTF_KEYUP, 0
      IF bCtrl THEN keybd_event enumKeys.keyControl, 0, KEYEVENTF_KEYUP, 0
      IF bAlt THEN keybd_event enumKeys.keyAlt, 0, KEYEVENTF_KEYUP, 0
     END IF

     END SUB

'Loop through a string and calls PressKey for each character (Does not
' parse strings like SendKeys)
     Public SUB PressString(BYVAL sString AS STRING, Optional bDoEvents AS Boolean = True)
     DO WHILE sString <> ""
      PressKey Mid(sString, 1, 1)
      SLEEP 20
      IF bDoEvents THEN DOEVENTS
      sString = Mid(sString, 2)
     LOOP
     END SUB

'Presses a specific key (this is used for keys that don't have a
' ascii equilivant)
     Public SUB PressKeyVK(keyPress AS enumKeys, Optional bHold AS Boolean, _
      Optional bRelease AS Boolean, Optional bCompatible AS Boolean)

     DIM nScan AS LONG
     DIM nExtended AS LONG

     nScan = MapVirtualKey(keyPress, 2)
     IF nScan = 0 THEN nExtended = KEYEVENTF_EXTENDEDKEY ELSE nExtended = 0
     nScan = MapVirtualKey(keyPress, 0)

     IF bCompatible THEN nExtended = 0
     IF NOT bRelease THEN keybd_event keyPress, nScan, nExtended, 0
     IF NOT bHold THEN keybd_event keyPress, nScan, KEYEVENTF_KEYUP OR nExtended, 0
     END SUB

'Returns (in the boolean variables) the status of the various Lock keys
     Public SUB GetLockStatus(bCapsLock AS Boolean, bNumLock AS Boolean, _
      bScrollLock AS Boolean)

     bCapsLock = GetKeyState(enumKeys.keyCapsLock)
     bNumLock = GetKeyState(enumKeys.keyNumLock)
     bScrollLock = GetKeyState(enumKeys.keyScrollLock)
     END SUB
掌柜推荐
 
 
¥477.00 ·
 
 
¥918.00 ·
 
 
¥370.00 ·
 
 
¥271.00 ·
 
 
¥995.00 ·
 
 
¥1,580.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-12-23 19:50:50