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

How can I delete a directory in a Zip file using .NET?
receiving string from c# to Java mistakes
No endpoint listening wcf/rest
How to add NT AUTHORITY\IUSR to Administrators group
Combobox in Syncfusion XlsIO
Creating a Strong Name dynamically, without Sn.exe
Why is my locally declared variable not being recognized in the finally block?
Comparing two different types with Entity Framework
loginview shows “welcome system-name/administrator” and logout for the first time page load
How to abort another thread in .NET, when said thread is executing Console.ReadLine?
OrderBy / ThenBy looping - nested Lists in C#
How to login external web site from asp.net web page? [closed]
ListPicker for WPF?
How to notify user of new message?
WPF Treeview Bindings
How do you iterate through JSON object in an ASP.NET MVC controller?

Categories

HOME
drupal
apache-storm
readdir
gaussian
x86-64
watson-iot
yuv
suitecrm
decoding
virtualenv
mongodb-replica-set
hql
web-worker
bookmarklet
ringcentral
openam
views
hl7-fhir
summernote
dev-c++
poisson
gulp-jshint
jms-topic
apm
overflow
foxpro
wordpress-rest-api
loopback
dropdownbox
minitest
android-geofence
usernotifications
aura-framework
binary-decision-diagram
emacs24
openxava
perldoc
playframework-2.3
cc
dmalloc
dynatable
timefield
dimensionality-reduction
virtualenvwrapper
periodic-processing
dday
nonblocking
kramdown
php-gd
android-networking
cakephp-2.6
gcc-warning
jeet-grid
static-files
crtdbg.h
launcher
diffmerge
nsurlrequest
sat4j
ccmenuitem
angular-file-upload
dateadd
smartxls
facebook-java-api
nativequery
lastinsertid
violation
extensibility
rbm
algol
metapost
openafs
states
beep
systrace
parsec
win-prolog
unordered-set
project-files
copyfile
symfony-1.2
sipdroid
response-time
http-response-codes
activescaffold
web-search
rpxnow
vista64
cons
stackless

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