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

Send multi messages via PostAsync within LuisDialog
How to add ComboBox column in XCeed DataGridControl (WPF)
Stream DateTime value,return Epoch value instead of “human” value
Finding a PowerPoint shape using Alternative text without looping through all shapes in C#
ASP.Net Page not loading when locale is en
Use c# variable in Jquery
How to use BeginInvoke in VB.NET
Looping through values in a string variable taken from a BizTalk message
Using RegEx to split strings after specific character
How to proper validate SSL certificate with X509Certificate2 on Mono and multiple platforms
How to persist and authenticate users from an MVC application to a Web API
Paged AD Query Sometimes Fails
How to pass multiple params to WebAPI?
HttpPut: “Index was out of range. Must be non-negative and less than the size of the collection” exception, but my data is still updated
Imgproc.FindContours return empty contours
linq SQL statements for joining two id with single list

Categories

HOME
qlikview
classification
postgresql
skype-for-business
oracle-sqldeveloper
service
postgresql-9.3
postsharp
arcgis
spotfire
spss
where
squeak
foreach
kendo-asp.net-mvc
runtime
olap
point-of-sale
virtualenv
captcha
sha1
ibatis
wallet
google-street-view
autologin
spring-webflow
openoffice-basic
descriptor
restructuredtext
bug-reporting
monad-transformers
serenity-js
dev-c++
google-drive-android-api
v4l2
gsuite
my.cnf
mongoose-im
launchd
dynamics-ax-2012-r3
delphi-2010
arp
andengine
visual-studio-debugging
kubectl
webspeech-api
incapsula
repeat
border-layout
maven-2
abide
mockserver
ngrok
file-conversion
file-descriptor
superclass
text-extraction
ocpjp
qtwebkit
xmldom
selection-sort
grib
lightspeed
blackberry-webworks
xcode7.1
airwatch
bbedit
wizard
oryx
android-contentresolver
controlpanel
wiql
magnet-uri
commercetools
windows-kernel
serial-communication
biginsights
nmock
vensim
eggplant
mri
touch-typing
dirname
webshim
azure-caching
rssi
farpoint-spread
svg-android
surfaceview
xcode5.1
mysql2
gwt2
auctex
django-tinymce
netzke
nserror
socketasynceventargs
win-prolog
rjs
flexbuilder
mismatch
service-layer
uccapi
ihtmldocument2
djangoappengine
wtsapi32

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