Space Bar

Can someone tell me how to code a space bar press in C# please?
ilovespam12000Asked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Do you want to TRAP a space bar keypress or SEND a space bar keypress?

If the latter, use SendKeys.Send().
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
sabeeshCommented:
string str = "ggggg" + (char)Keys.Space  + "rrrrr";
            MessageBox.Show(str);
0
 
ilovespam12000Author Commented:
Idle Mind - I need to send a space bar keypress
0
 
ilovespam12000Author Commented:
Sams publishing assumes a key was pressed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.