c#


How do I make my application to know when the spacebar key is pressed globally on a low-level?


I want to call on a method to execute whenever the space key is pressed whether my application is on focus or running in the background. How do I this in C# ? Let s say the method to call on is sendData(). How do I hook my keyboard on a level level to execute the sendData() method whenever the space key is pressed using C#.
You need to listen for a key press, in your case you're looking for ConsoleKey.Spacebar, the documentation for it here: ConsoleKey Enum
Here is a quick and dirty sample:
Console.WriteLine("Press Spacebar to send data");
while (!(Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Spacebar))
{
// iterate something (or nothing)
}
sendData(); // call your method afterwards
It's important to note that Console.ReadKey is blocking. My code sample is just to illustrate some basics.

Related Links

Ajax Dropdownlist using cascading dropdownlist in asp.net
Adding textbox value with button in C#
How to show the tooltip without any time duration?
How can i hide in game view a ui button and show the button when pressing the escape key?
TCP Connection. best way to handle multiple connections [duplicate]
Send POST request with Image from Unity3D
How to make default Password Reset functionality work in ASP.NET Core
UriTemplate Matching Email
Error handling between web api and angular 2 client
Get Duplicates in List and Edit Item
Should I await a 'async Task' function if I don't care its return value? [duplicate]
Autofac open generics: factory IIndex based on <U>
string with StingBuilder error c#
Mono SQLite with CF 3.5
EWS Oauth Exception: The request failed. The remote server returned an error: (401) Unauthorized
Reports in MS Word. Any library? [closed]

Categories

HOME
dronekit
dynamic
arcgis
boxplot
spss
redhawksdr
perl6
multipartform-data
opacity
markdown
phpexcel
digital
aspectj
unreal-engine4
point-of-sale
websharper
email-attachments
tmux
hql
dat.gui
web-worker
versioning
samba
ringcentral
project-reactor
aws-devicefarm
minimagick
devexpress-mvc
edsdk
akamai
opencsv
apache-falcon
sampling
perf
extern
stdin
nscollectionview
lfe
server-side-swift
pyexcel
jquery-ui-slider
irr
test-kitchen
scrapinghub
risc
jenkins-2
playframework-2.3
chain
node.js-client
apache-commons-cli
google-scholar
portaudio
qudpsocket
gevent
firebase-polymer
xcode7.1
rowname
falcon
mrunit
jmh
pyshark
paypal-subscriptions
music-player
jersey-test-framework
datamodel
recode
redquerybuilder
persian
jain-sip
page-flipping
pushwoosh
eggplant
valdr-bean-validation
accpac
data-quality-services
cl.exe
illegalargumentexception
diffmerge
growl
drawable
serializer
nspopupbutton
traceur
connections
mongoid4
netbeans-plugins
ekevent
complete
xcode5.1
ia-32
pyxplot
algol
invalidoperationexception
inflate
report-viewer2010
jquery-1.8
databus
states
sup
flatten
bash4
mysql-connector
win-prolog
xpolog
symfony-1.2
azure-appfabric
conditional-operator
nstoolbar
konsole
datadude
time-management

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App