Solved

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

Posted on 2010-11-17
9
1,013 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
  • 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 85

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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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 85

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now