Space Bar

Can someone tell me how to code a space bar press in C# please?
Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Make sure the app has focus, then use SendKeys.Send():

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.


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().
Cloud Class® Course: C++ 11 Fundamentals

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

string str = "ggggg" + (char)Keys.Space  + "rrrrr";
ilovespam12000Author Commented:
Idle Mind - I need to send a space bar keypress
ilovespam12000Author Commented:
Sams publishing assumes a key was pressed.
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.