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 to get the path for the SetBinding method on an IContentItemProxy in LightSwitch?
c# SortableBindingList cannot sort columns with Object values
Automapper limitations in terms of performance
ANTLR4 (C#) - Error
LINQ to SQL decrypt value before populating object
Loading DLLs at runtime in C#
How to create an Enter button?
Why is ProtoBuf-Net's performance so poor when serializing a list of strings?
Search Results In Dropdown Below Textbox Like Google (ASP)
C# XAML ScrollViewer to work without MaxHeight
Can I cast an integer to a long when the types are generic/boxed?
How to caclulate FixedPage dimensions
How to run “Run Bar” commands?
Allowing ad-hoc expressions over IEnumerable<MyObj>
How to Set up Activeflag if we have CorpFlag?
How to load/Unload tile chunks faster(C#)

Categories

HOME
gulp
pelican
watson-iot
singleton
open-search-server
google-search-appliance
email-attachments
http-status-codes
expo
lambda-calculus
greensock
game-engine
civicrm
sonarlint
gomobile
angular2-pipe
onclicklistener
chartist.js
mongoose-im
formtastic
scripting-language
resx
schedule
mplab
repeat
motion
jslider
linkurious
ui-grid
jquery-ui-slider
definition
servicebus
risc
niagara-ax
anonymous-function
beanshell
sp
nsalert
codesniffer
tsc
robotc
indoor-positioning-system
access-violation
change-password
clique
cexception
skbio
matlab-engine
javapackager
gulp-cdnizer
exchange-server-2007
jsoncpp
tess4j
textblob
mergecursor
radgrid
wingdb
indices
novell
yosemite
zoneminder
system.net
nest-initiative
scjp
angular-file-upload
rda
traceur
class-library
mixradio
grape-api
aspnet-compiler
nsnumber
mosix
wordbreaker
cocotron
jquery-1.8
beep
systrace
helicontech
execjs
soapexception
qvariant
designated-initializer
n2
onunload
azure-appfabric
nyromodal
newspeak
rpxnow

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile