Solved

VB Coding for a spacebar.  Not Sendkey(" ")

Posted on 2010-11-17
9
1,061 Views
Last Modified: 2012-05-10
I am trying to simulate a spacebar event on the keyboard so that I can check a radio button on a third party application.  Sending a character space is not the problem but I just need to choose the radio button.
0
Comment
Question by:8thFloor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 41

Expert Comment

by:graye
ID: 34157000
Take a look at the RaiseKeyEvent class... that will get you going

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.raisekeyevent(v=VS.100).aspx
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 34159223
Try using keybd_event() instead:
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)

    Public Sub Foo()
        keybd_event(Keys.Space, 0, 0, 0)
    End Sub

Open in new window

0
 
LVL 41

Expert Comment

by:graye
ID: 34161084
Is this for VB6 or VB.Net?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:omegaomega
ID: 34161726
Hello, 8thFloor,

Re: "...I just need to choose the radio button."

Does the radio button have an accelerator key?  (Is it unique?)

Cheers,
Randy
0
 

Author Comment

by:8thFloor
ID: 34165767
Thanks for the responses.  What I am trying to do is simulate keystrokes in an application that is running on Windows.  This is a third party application that I only have the executable for. So using SendKeys and tabs and ALT key shortcuts, I am able to get to the radio button that I need to select in order to continue.  To select a radio button without a mouse is the spacebar.  That is what I am trying to do.  Am I approaching this in the way?  
0
 
LVL 12

Expert Comment

by:omegaomega
ID: 34175842
Hello, 8thFloor,

I do not understand.  In your original post you said "Sending a character space is not the problem but I just need to choose the radio button." and indicated that you didn't want to use SendKeys.  But in your last post it sounds like you aren't having a problem choosing the radio button and don't mind using SendKeys.

What is the actual question to which you are seeking an answer?

BTW.  I recommend avoiding SendKeys if at all possible, because you cannot absolutely guarantee which application will pick up the keystrokes that were sent.

Cheers,
Randy

0
 
LVL 41

Accepted Solution

by:
graye earned 125 total points
ID: 34178057
Well, if I understood the problem (which I'm beginning to doubt)...  the issue is that you want your VB application (6 or .Net, still not clear) to send keystrokes to another running application.   If I'm not mistaken, SendKeys only sends to the "active" application (which in this case would be your applicaiton... not the other one).

There are low-level APIs that perform the function to send keys to another running process...
http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx
0
 

Author Comment

by:8thFloor
ID: 34188451
My apologies for not making myself clearer. I would rather not use senkeys as well but is there a general accepted solution to running an un-manned executable that needs prompts from a user?  I was able to use Sendkeys to process most of the prompts but when it came to selecting a radio button, sending a space does not work.  I am writing this program is .NET.
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 125 total points
ID: 34188545
So using keybd_event() as suggested in my post back here did not work?
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_26621661.html#34159223

You can target the application directly using Win APIs such as SendMessage() but the approach is MUCH more involved.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question