Solved

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

Posted on 2010-11-17
9
1,037 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

816 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

8 Experts available now in Live!

Get 1:1 Help Now