Solved

Space Bar

Posted on 2006-11-28
8
1,008 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
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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