Solved

Space Bar

Posted on 2006-11-28
8
1,011 Views
Last Modified: 2008-01-09
Can someone tell me how to code a space bar press in C# please?
0
Comment
Question by:ilovespam12000
[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
8 Comments
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 18033637
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18034123
Do you want to TRAP a space bar keypress or SEND a space bar keypress?

If the latter, use SendKeys.Send().
0
 
LVL 8

Expert Comment

by:sabeesh
ID: 18034218
string str = "ggggg" + (char)Keys.Space  + "rrrrr";
            MessageBox.Show(str);
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!

 

Author Comment

by:ilovespam12000
ID: 18037086
Idle Mind - I need to send a space bar keypress
0
 

Author Comment

by:ilovespam12000
ID: 18037175
Sams publishing assumes a key was pressed.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 18037497
Make sure the app has focus, then use SendKeys.Send():
http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys.send.aspx

Something like:

    SendKeys.Send(" ");

If that doesn't work then you may need to use Win APIs to simulate the keypress at the keyboard level.  You can use keybd_event() or SendInput() for that.

Below are some links that show them being used, though not for Space bar in particular.

keybd_event():
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20813844.html

SendInput():
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21650933.html
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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