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

OpenXML SDK 2.5 unreadable content
SmoothStreaming Player in NodeJS
Get Index of Item in Listview From Button in Item
Dynamically convert object based on property type
Interfaces exposing generic overload. How to DRY here?
Listbox with thousand of images in a wrappanel
“EntityType has no key defined”, but I added [Key], why?
Sliding view from the bottom in a Universal Windows App
Why isnt my HttpClient timing out? [duplicate]
C# list users that have a quota on a drive
Asp.Net ViewState performance
Getting NullReferenceExeption in unity using dreamlo scoreboards
Left Outer Join using LINQ Method Syntax
Add Keyboard short cut to WinForm App
Error while trying to publish a test web app
MS UI Automation- AddAutomationHandler not firing

Categories

HOME
swift3
stata
ftp
packet
snappy
azure-database-mysql
boxplot
x509certificate
aggregate-functions
autocad
markdown
handlebars.js
osx-yosemite
ofbiz
loader
ithit-webdav-server
rollupjs
mongoose-im
pydub
cache-control
ponylang
rbac
file-descriptor
collation
text-extraction
head
emacs24
dynamic-linking
bioperl
activesupport
aot
androiddesignsupport
liferay-ide
jspx
scriptengine
instaparse
git-cherry-pick
audiorecord
phpdesigner
ideavim
wizard
dcast
jquery-draggable
google-app-engine-php
yfiles
opendolphin
app-data
gtkwave
kramdown
android-facebook
producer-consumer
exchange-server-2007
borland-c++
firewire
strcpy
mathics
caption
crystal-reports-7
fedena
system.io.packaging
xmlserializer
redmine-plugins
worklight-appcenter
step
visual-studio-setup-proje
lettuce
opencobol
xps
sqldatasource
jython-2.5
servicemanager
urlfetch
linqdatasource
orchestration
netzke
beep
diazo
cherokee
httppostedfilebase
designated-initializer
cinder
mysql-logic
large-data-volumes
lts

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App