Solved

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

Posted on 2010-11-17
9
1,028 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

15 Experts available now in Live!

Get 1:1 Help Now