|
-
Jan 12th, 2001, 04:25 PM
#1
Thread Starter
Member
SendKeys turn off the NumLock, Capslock, & etc
When using the following code, the NumLock, CapsLock, and Scroll gets Turn off.
AppActivate IDIdentifier, False
'Send a Ctrl-A (Select All) and Ctrl-Ins (Copy)
SendKeys "^a"
SendKeys "^{INSERT}"
I would like to prevent this from happening. My alternate solution was to turn the keys on through the key_bd_event.
However it only worked in step mode. Any ideas?
Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Public Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Const VK_NUMLOCK = &H90
Public Const KEYEVENTF_KEYUP = &H2
Public Const VK_Capital = &H14
Dim AllKeys(255) As Byte
Dim NumLock As Byte
Dim retVal As Long
retVal = GetKeyboardState(AllKeys(0))
NumLock = AllKeys(VK_NUMLOCK)
'Set focus to ID ToolTip
AppActivate IDIdentifier, False
'Send a Ctrl-A (Select All) and Ctrl-Ins (Copy)
SendKeys "^a"
SendKeys "^{INSERT}"
DoEvents
If NumLock = 1 Then
keybd_event VK_NUMLOCK, 0, 0, 0
keybd_event VK_NUMLOCK, 0, KEYEVENTF_KEYUP, 0
MsgBox NumLock
End If
-
Jan 12th, 2001, 04:44 PM
#2
Try using the Wait subparameter of SendKeys.
SendKeys string[, wait]
The SendKeys statement syntax has thesenamed arguments:
Part Description
string Required.String expression specifying the keystrokes to send.
Wait Optional.Boolean value specifying the wait mode. If False (default), control is returned to theprocedure immediately after the keys are sent. If True, keystrokes must be processed before control is returned to the procedure.
-
Jan 12th, 2001, 05:08 PM
#3
Instead of turning numlock back on, you could avoid using SendKeys at all. Turning numlock off is a known bug in SendKeys. You could use the key_bd_event to press the Ctrl-A and Ctrl-Ins.
eg
Code:
Option Explicit
Private Const VK_CONTROL = &H11
Private Const VK_INSERT = &H2D
Private Const VK_NUMLOCK = &H90
Private Const KEYEVENTF_KEYUP = &H2
Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As Byte) As Integer
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Command1_Click()
Dim retVal As Long
Dim VK_A As Integer
AppActivate "Untitled - Notepad"
'DoEvents
' find the Virtual key code for char A
VK_A = VkKeyScan(Asc("a"))
' send CTRL-A
' press CTRL down
keybd_event VK_CONTROL, 0, 0, 0
' press A down
keybd_event VK_A, 0, 0, 0
' release the A key
keybd_event VK_A, 0, KEYEVENTF_KEYUP, 0
' release CTRL key
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
' send CTRL-INS
' press CTRL down
keybd_event VK_CONTROL, 0, 0, 0
' press INS down
keybd_event VK_INSERT, 0, 0, 0
' release the INS key
keybd_event VK_INSERT, 0, KEYEVENTF_KEYUP, 0
' release CTRL key
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|