how do i send the enter key?
Printable View
how do i send the enter key?
VB Code:
SendKeys "{ENTER}"
Just in case you missed the post in the other file. HOw do I determine left from right ctrl keys and the two enter keys?
If you've got MSDN, look up SendKeys, it has the list of Keys that you can use their.
And.... I think the keyboard sees the 2 Ctrl Buttons as the same key, and won't know the difference between the 2.
If you want to differentiate between two control keys you are going to have to write a keyboard hook program and trap the scan codes of the keys. I believe scan code of both controls are different. You can get lot of such programs on www.pscode.com/vb
Well... I used a program which displays the values for the keys, and it returned 18 for both Alt Buttons...
pc Madness: I have a couple of programs that have different functions for the two ctrl keys and alt keys. That program can tell which ctrl or alt key has been pressed. I gotta figure out how it does that. Same with the enter keys.
techyspecy: Thanks, I'll check out those programs and let you know.
Here's how to do that.Quote:
Originally posted by Ephesians
pc Madness: I have a couple of programs that have different functions for the two ctrl keys and alt keys. That program can tell which ctrl or alt key has been pressed. I gotta figure out how it does that. Same with the enter keys.
techyspecy: Thanks, I'll check out those programs and let you know.
Place this code in standard module.
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Const WH_KEYBOARD_LL = 13
Public Const HC_ACTION = 0
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public Function KeyboardHookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If (nCode = HC_ACTION) Then
If (wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN) Then
CopyMemory k, ByVal lParam, Len(k)
MsgBox k.vkCode
endif
endif
KeyboardHookProc = CallNextHookEx(hHook, nCode,
wParam, ByVal lParam)
end function
'instead of scan code, you look for Virtual key code. Vistual key
'code for left ctrl is 162 while for right ctrl key its 163.
place this in general declaration of form
Dim hHook As Long
Place this code in the command button click event on the form ...
Private sub command1_click()
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf
KeyboardHookProc, App.hInstance, 0)
end sub
Please add all constants and API's (if i am missing any) to the standard module .....
This will do the stuff for you ..........
Now that's what I'm talking about.. Thanks a bunch!
You can also use GetAsyncKeyState()VB Code:
Option Explicit Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private Const VK_CONTROL = &H11 Private Const VK_LCONTROL = &HA2 Private Const VK_RCONTROL = &HA3 Private Const VK_MENU = &H12 Private Const VK_LMENU = &HA4 Private Const VK_RMENU = &HA5 Private Const VK_SHIFT = &H10 Private Const VK_LSHIFT = &HA0 Private Const VK_RSHIFT = &HA1 Private Const VK_RETURN = &HD Private Sub Form_Load() Dim lKey As Long ' Wait for Keyboard Buffer to Clear For lKey = 0 To 255 Do While GetAsyncKeyState(lKey) <> 0 DoEvents Loop Next ' Turn on Timer Timer1.Interval = 100 End Sub Private Sub Timer1_Timer() Dim lKey As Long ' Check all Key States For lKey = 0 To 255 If GetAsyncKeyState(lKey) <> 0 Then Select Case lKey Case VK_CONTROL Debug.Print "CONTROL" Case VK_MENU Debug.Print "ALT" Case VK_SHIFT Debug.Print "SHIFT" Case VK_LCONTROL Debug.Print "LEFT CONTROL" Case VK_LMENU Debug.Print "LEFT ALT" Case VK_LSHIFT Debug.Print "LEFT SHIFT" Case VK_RCONTROL Debug.Print "RIGHT CONTROL" Case VK_RMENU Debug.Print "RIGHT ALT" Case VK_RSHIFT Debug.Print "RIGHT SHIFT" Case VK_RETURN Debug.Print "RETURN/ENTER" End Select End If Next End Sub
I am sorry ephseians, i missed a important part ...
add this also to standard module .......
Global hHook As Long
Public Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Dim k As KBDLLHOOKSTRUCT