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

C# Calculate the image scroll with scrollbar
stream audio and video data separately
Azure Active Directory Authentication with Azure Mobile Services Failed
Xamarin Parse Component refresh current user
How to use Automapper to map an object to an interface at a different level?
ASP.Net C# equivalent to Coldfusion cfoutput GROUP
HtmlAgilityPack convert XPath query to LINQ
How to assign System.Drawing.Color to Microsoft.Office.Interop.Excel.ColorFormat
Construct a list of wpf Hyperlink elements from an XML source file using Linq
Exception while using Regex with richtextbox in C#
Is there is a way to generate “simple” url with #Url.Action?
How to get the cell index of textbox in my gridview
C# selenium max sessions
asp mvc, having trouble understanding composite models
Default text for checkable combobox
WPF MVVM c# binding textbox

Categories

HOME
stanford-nlp
service
jenkins-pipeline
gaussian
stdout
crm
spss
google-docs-api
checkpoint
jshell
opacity
scapy
google-my-business-api
camunda
opengrok
tag-cloud
openscad
reportlab
orange
screen-scraping
wai-aria
advertising
gsuite
ppp
my.cnf
grunt-contrib-uglify
emr
spock
csproj
semantic-ui-react
xlib
lines
log4net-configuration
jcr
luhn
webmock
dropdownbox
odp.net
border-layout
sdl-2
android-databinding
sknode
compiled-query
aspnetboilerplate
encoder
django-tables2
openxava
gige-sdk
nsalert
scanf
sqlproj
scikit-image
foreground
supervised-learning
jde
sqlxml
nugetgallery
std
fadein
videoview
ewam
gtkwave
wiql
gnu-sort
gulp-cdnizer
jts
personality-insights
textblob
euro
conkeror
system.io.packaging
nsurlrequest
lwuit
vundle
selenium-grid2
azure-worker-roles
time-frequency
serializer
banana-pi
jsmpp
starling-framework
flask-mongoengine
boofcv
maven-javadoc-plugin
nokogiri
stringstream
asp.net-4.0
nx
generator-expression
cron4j
django-1.4
jqueryi-ui-buttonset
mcpd
rjs
xhtmlrenderer
norton
versions
code-golf
ihtmldocument2
zend-acl
projectgen
ffdshow

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