Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > API > Sending ReturnKey with SendMessage


Reply
 
Thread Tools Display Modes
  #1  
Old 03-19-2003, 10:17 PM
EpcH's Avatar
EpcH EpcH is offline
Contributor
 
Join Date: Jan 2003
Location: USA, CT
Posts: 460
Default 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}"
Reply With Quote
  #2  
Old 03-19-2003, 10:22 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

You might try SendMessage with WM_CHAR.

SendMessage hwnd, WM_CHAR, vbKeyReturn, Byval 0
Reply With Quote
  #3  
Old 03-19-2003, 10:36 PM
EpcH's Avatar
EpcH EpcH is offline
Contributor
 
Join Date: Jan 2003
Location: USA, CT
Posts: 460
Default

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
Reply With Quote
  #4  
Old 03-19-2003, 10:55 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

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.
Reply With Quote
  #5  
Old 03-19-2003, 11:36 PM
EpcH's Avatar
EpcH EpcH is offline
Contributor
 
Join Date: Jan 2003
Location: USA, CT
Posts: 460
Default

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 :)
Reply With Quote
  #6  
Old 03-20-2003, 12:31 AM
EpcH's Avatar
EpcH EpcH is offline
Contributor
 
Join Date: Jan 2003
Location: USA, CT
Posts: 460
Default

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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing and sending through winsock. AtonalPanic Communications 1 03-04-2003 07:46 PM
sendmessage problem dmlx90 API 6 04-23-2002 05:13 PM
SendMessage Problems Luber25 API 4 03-12-2002 04:32 PM
How to use SendMessage API pinster API 2 03-12-2002 04:26 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->