Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-11-17
9
Medium Priority
?
1,095 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
Technology Partners: 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 500 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 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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