 |
 |

03-19-2003, 10:17 PM
|
 |
Contributor
|
|
Join Date: Jan 2003
Location: USA, CT
Posts: 460
|
|
Sending ReturnKey with SendMessage
|
How can one send a Return command with SendMessage API ? I was using sendkeys but I want replace sendkeys with SendMessage in my code.
How can I do this with sendmessage API
SendKeys "{ENTER}"
|
|

03-19-2003, 10:22 PM
|
 |
Obsessive OPtimizer
Administrator * Guru *
|
|
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
|
|
|
You might try SendMessage with WM_CHAR.
SendMessage hwnd, WM_CHAR, vbKeyReturn, Byval 0
|
|

03-19-2003, 10:36 PM
|
 |
Contributor
|
|
Join Date: Jan 2003
Location: USA, CT
Posts: 460
|
|
Thanks for the information,
Don't I need to declare WM_Char first as a constant and initialize it? Like the examples below, I found these in the code library section, and I wonder how can I get all the constants for messaging?
Code:
'Possible key messages
Private Const VK_ADD = &H6B
Private Const VK_ATTN = &HF6
Private Const VK_BACK = &H8
Private Const VK_CANCEL = &H3
Private Const VK_CAPITAL = &H14
Private Const VK_CLEAR = &HC
Private Const VK_CONTROL = &H11 '"Alt" Button
Private Const VK_CRSEL = &HF7
Private Const VK_DECIMAL = &H6E
Private Const VK_DELETE = &H2E
Private Const VK_DIVIDE = &H6F
Private Const VK_DOWN = &H28
Private Const VK_END = &H23
Private Const VK_EREOF = &HF9
Private Const VK_ESCAPE = &H1B
Private Const VK_EXECUTE = &H2B
Private Const VK_EXSEL = &HF8
Private Const VK_F1 = &H70
Private Const VK_F10 = &H79
Private Const VK_F11 = &H7A
Private Const VK_F12 = &H7B
Private Const VK_F13 = &H7C
Private Const VK_F14 = &H7D
Private Const VK_F16 = &H7F
Private Const VK_F17 = &H80
Private Const VK_F18 = &H81
Private Const VK_F19 = &H82
Private Const VK_F2 = &H71
Private Const VK_F20 = &H83
Private Const VK_F15 = &H7E
Private Const VK_F21 = &H84
Private Const VK_F22 = &H85
Private Const VK_F23 = &H86
Private Const VK_F24 = &H87
Private Const VK_F3 = &H72
Private Const VK_F4 = &H73
Private Const VK_F5 = &H74
Private Const VK_F6 = &H75
Private Const VK_F7 = &H76
Private Const VK_F8 = &H77
Private Const VK_F9 = &H78
Private Const VK_HELP = &H2F
Private Const VK_HOME = &H24
Private Const VK_INSERT = &H2D
Private Const VK_LBUTTON = &H1
Private Const VK_LCONTROL = &HA2
Private Const VK_LEFT = &H25
Private Const VK_LMENU = &HA4
Private Const VK_LSHIFT = &HA0
Private Const VK_MBUTTON = &H4
Private Const VK_MENU = &H12
Private Const VK_MULTIPLY = &H6A
Private Const VK_NEXT = &H22
Private Const VK_NONAME = &HFC
Private Const VK_NUMLOCK = &H90
Private Const VK_NUMPAD0 = &H60
Private Const VK_NUMPAD1 = &H61
Private Const VK_NUMPAD2 = &H62
Private Const VK_NUMPAD3 = &H63
Private Const VK_NUMPAD4 = &H64
Private Const VK_NUMPAD5 = &H65
Private Const VK_NUMPAD6 = &H66
Private Const VK_NUMPAD7 = &H67
Private Const VK_NUMPAD8 = &H68
Private Const VK_NUMPAD9 = &H69
Private Const VK_OEM_CLEAR = &HFE
Private Const VK_PA1 = &HFD
Private Const VK_PAUSE = &H13
Private Const VK_PLAY = &HFA
Private Const VK_PRINT = &H2A
Private Const VK_PRIOR = &H21
Private Const VK_RBUTTON = &H2
Private Const VK_RCONTROL = &HA3
Private Const VK_RETURN = &HD 'AKA "Enter"
Private Const VK_RIGHT = &H27
Private Const VK_RMENU = &HA5
Private Const VK_RSHIFT = &HA1
Private Const VK_SCROLL = &H91
Private Const VK_SELECT = &H29
Private Const VK_SEPARATOR = &H6C
Private Const VK_SHIFT = &H10
Private Const VK_SNAPSHOT = &H2C
Private Const VK_SPACE = &H20
Private Const VK_SUBTRACT = &H6D
Private Const VK_TAB = &H9
Private Const VK_UP = &H26
Private Const VK_ZOOM = &HFB
|
|

03-19-2003, 10:55 PM
|
 |
Obsessive OPtimizer
Administrator * Guru *
|
|
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
|
|
|
Yes, of course. Since the WM_CHAR constant is Win32 api and not part of VB, you must declare it. You will find many declares, constants and user-defined types by using your API Viewer. Find the shortcut to it where you open VB, or use it as an addin.
|
|

03-19-2003, 11:36 PM
|
 |
Contributor
|
|
Join Date: Jan 2003
Location: USA, CT
Posts: 460
|
|
Code:
Private Const WM_CHAR = &H102
SendMessage bWnd, WM_CHAR, 63, ByVal 0& ' char "?"
SendMessage bWnd, WM_CHAR, 13, ByVal 0& ' carriage return
Above code sends "?" text to target application, but the carriage return does not work. I also tried sending vbkeyreturn but still not working.
Any Idea what may cause this?
Thanks for already helping so far so much :)
|
|

03-20-2003, 12:31 AM
|
 |
Contributor
|
|
Join Date: Jan 2003
Location: USA, CT
Posts: 460
|
|
I figured out my problem. It maybe useful for someone else, so I am posting.
I used Spy++ tool that comes with Visual Studio to observe the messages. I realized that when I use SendMessage function, for every Char, there are actually two messages.
For example:
Code:
SendMessage bWnd, WM_CHAR, 13, ByVal 0& ' char "?"
SPY++ shows an additional windows message following after above code that returns to the caller, and in my case this was the reason of not functioning.
So I used PostMessage API , fire and forget type approach, and it is working fine now.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|