ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] Num Lock ¼Æ¦rÁ䪬ºA¨ú±o

[µo°Ý] Num Lock ¼Æ¦rÁ䪬ºA¨ú±o

VBA µo¥X sendkeys ".... " «á±`±` ·|¤£ª¾¦ó­ì¦] ¼vÅT¼Æ¦rÁä鎻 NUMLOCKª¬ºA³Q§ïÅܤF¡A
¦bµo¥X¤@­Ó sendkeys "{NUMLOCK}" ¨Ã¤£¯à¦^´_­ì¨Óª¬ºA
°ÝÃD¬OµLªk´x´¤ numlock ªº¯u¥¿ª¬ºA¡A¨Ï¥Î windows API ¤]¨S¯à´x´¤ª¬ºA
     (§@·~¨t²Î WIN 10)
¦³½Ð½å¹F¨ó§U

' API declaration

'Key board events operation
Private Declare Sub keybd_event Lib "user32" ( _
  ByVal bVk As Byte, _
  ByVal bScan As Byte, _
  ByVal dwFlags As Long, _
  ByVal dwExtraInfo As Long)
  
'Get key status
Private Declare Function GetKeyState Lib "user32" ( _
  ByVal nVirtKey As Long) As Integer

'======°ÝÃD¨Ò ¡G­n¨Ï numLock «O«ù«G¿O ==========
Sub LightUpNUMLOCK()
   
    SendKeys "^g^a{DEL}"     '°eÁä­È¡A®ø°£§Y®É¹Bºâµøµ¡¤º¸ê®Æ¡F¥i¯àÅܧó¤F NumLock «G¿Oª¬ºA
'   SendKeys "{NUMLOCK}", True   '¤£¯à¨Ï numlock ¨C¦¸«O«ù¿O«G
'  debug.print GetKeyState(vbKeyNumlock)
'¨Ï¥ÎAPI ¨ú±o NumLock ª¬ºA¡A°²¦p¿O¬Oº¶ªº´N°e  NumLock key  ¨Ï¿O¦A«G
    If GetKeyState(vbKeyNumlock) = 0 Then    '¡ö ¦¹«ü¥OµLªk¥¿½TŪ¨úª¬ºA  
        SendKeys "{NUMLOCK}", True
    End If
End Sub

¥»©«³Ì«á¥Ñ jackyq ©ó 2016-9-26 17:51 ½s¿è

SendKeys "^g^a{DEL}"  , True   '   If GetKeyState(vbKeyNumlock) = 0 Then  '¡ö ¦¹«ü¥O¥i¥¿½TŪ¨úª¬ºA  

SendKeys "{NUMLOCK}  ¦n¹³¦³ bug À³¸Ó¤]¨Sªk¥Î

TOP

¥»©«³Ì«á¥Ñ PKKO ©ó 2016-9-26 21:38 ½s¿è

¦^´_ 1# Scott090


    ¬Û¦P§xÂZ+1
¤p§Ì¤]´¿¸g¬ã¨s¹L³\¤[
https://support.microsoft.com/zh-tw/kb/179987
¸Ñ¨M¤è¦¡¬°¼W¥[¤@¦æ    DoEvents=>¦ý...µL®Ä....
¨D¸Ñµª+1
PKKO

TOP

SendKeys ¦³ bug
¥i¥H¹Á¸Õ¥Î  keybd_event ¥h°e

TOP

¦^´_ 2# jackyq

¦b #1 µo¤å¤¤ªº¨Ò¤l¡ASendKeys "^g^a{DEL}"  , True ¤]¬O¦³¸Õ¹Lªº¡A
If GetKeyState(vbKeyNumlock) = 0 then '¦b win 10 ¨ú±oªº¨Ã«DíºAªº¸ê°T
¿Oº¶®É¤]·|¦³1¡A¿O«G®É¤]·|¦³ 0¡C¦b¨ä¥LªºOS¨t²Î§Ú¬O¤£ª¾¹D·|¬O«ç¼Ë

TOP

¦^´_ 5# Scott090

§â©Ò¦³  SendKeys ²¾°£
¥u¯d debug.print GetKeyState(vbKeyNumlock)  ¤@¥y

Numlock ¤â°ÊÃö³¬ , Æ[¹î GetKeyState(vbKeyNumlock) ¬O§_¥¿½T
Numlock ¤â°Ê¶}±Ò , Æ[¹î GetKeyState(vbKeyNumlock) ¬O§_¥¿½T
¦pªG³£¥¿½TµL»~, ªí¥Ü¬O SendKeys ¦b§@©Ç

TOP

¦^´_ 6# jackyq
¦^´_ 3# PKKO

·íµM sendkeys «Ü§@©Ç
¥¦¤£¶È¼vÅT numlock, capslock, scroll, ÁÙ·|²ö¦W¨ä§®¶]¥X©w¸q¦WºÙ°Ñ·Ó­þ¤@­Ó¦ì¸m!!
#3¼Ó ´£¨ì https://support.microsoft.com/zh-tw/kb/179987

³o¥÷¤å¥óªº¸Ñ¨M¤è®×¦³3¡A «e2­Ó¸Õ¤F³£¤£¦æ
¦A¸Õ²Ä3­Ó«Ü¨±°jªº¤è®×¦p¤U¡A¦n¹³¥i¥Hí©wªº¸Ñ¨M°ÝÃD (win10)

Option Explicit

' API declarations:

Private Declare Sub keybd_event Lib "user32" _
   (ByVal bVk As Byte, _
    ByVal bScan As Byte, _
    ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
   
Private Declare Function GetKeyboardState Lib "user32" _
   (pbKeyState As Byte) As Long

Private Declare Function SetKeyboardState Lib "user32" _
   (lppbKeyState As Byte) As Long
   
   ' Constant declarations:
      Const VK_NUMLOCK = &H90
      Const VK_SCROLL = &H91
      Const VK_CAPITAL = &H14
      Const KEYEVENTF_KEYUP = &H2
   
'https://support.microsoft.com/zh-tw/kb/179987
'Resolution:
'Determine the setting of the NumLock key prior to using SendKeys.
'Then, turn off the NumLock before using SendKeys.
'After using SendKeys,reset the NumLock to its previous setting.
'This is accomplished using the GetKeyboardState, keybd_event and SetKeyboardState API functions.
'================================================================================================

Private Sub test()     '´ú¸Õ sendkeys
    presetNumlock
   
    SendKeys "^g^a{DEL}" ', True
   
    TurnNumlock

End Sub


Sub presetNumlock()
     Dim bKeys(0 To 255) As Byte
     Dim LockState%
      
    'Get status of the 256 virtual keys
    GetKeyboardState bKeys(0)
   
    'turn off the num_lock key
    If bKeys(vbKeyNumlock) = 1 Then
        TurnNumlock
    End If
    DoEvents       '¤@©w­n ?

End Sub

Sub TurnNumlock()
    'Simulate Key Press
    keybd_event vbKeyNumlock, 1, 0, 0
    'Simulate Key Release
    keybd_event vbKeyNumlock, 1, KEYEVENTF_KEYUP, 0
End Sub

TOP

¦^´_ 7# Scott090


SendKeys ¬JµM·|§@©Ç, ¤£¦p³o³¡¤À°®¯Ü¤£¥Î¥¦

Public Sub Sendkey2(keyArray)
  For w = LBound(keyArray) To UBound(keyArray): Call keybd_event(keyArray(w), 0, &H1, 0): Next
  For w = LBound(keyArray) To UBound(keyArray): Call keybd_event(keyArray(w), 0, &H3, 0): Next
End Sub

Public Sub  clear_win  (                 )
Sendkey2 Array(vbKeyControl, vbKeyG)
Sendkey2 Array(vbKeyControl, vbKeyA)
Sendkey2 Array(vbKeyDelete)
If GetKeyState(vbKeyNumlock) = 1 Then
   Sendkey2 Array(vbKeyNumlock)
End If
End Sub

TOP

¦^´_ 8# jackyq


    Sendkey2 Array(vbKeyControl, vbKeyG, vbKeyControl, vbKeyA, vbKeyDelete)
¹êÅ窺µ²ªG¡ANum_Lock ·|«O«ù­ì¨Ó¥¼°e key ¤§«eªºª¬ºA

ÁÂÁÂ

TOP

¦^´_ 8# jackyq


    ©ñ¨ì¹ê»ÚªºÀ³¥Î¡A¤£½× 7# ©Î 8# ªº¤èªk³£·|²£¥Í¤U¦C"¤£¬Û¤z"ªº¸ß°Ýµe­±¡G
1.jpg

sendkeys ªº bug ÁÙ¬O¨S¦³Á×¹L

1.jpg (12.08 KB)

1.jpg

TOP

        ÀR«ä¦Û¦b : ¤f»¡¦n¸Ü¡B¤ß·Q¦n·N¡B¨­¦æ¦n¨Æ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD