Question Run application on keypress

keyboard1333

Member
Joined
Nov 18, 2012
Messages
11
Programming Experience
1-3
Greetings everyone,
I'm looking to launch my cmd on pressing a certain key, using a vb.net console applicaiton, but even when the applicaiton is not in focus...
I have absolutely no idea how to do this...
Any suggestions?
 
I'm not sure that you have actually provided a full explanation. Are you saying, without actually saying, that you have a WinForms app and you want it to start a Console app when the user presses a particular key combination? If so then you'll need to use the RegisterHotKey API to detect a key press when your app doesn't have focus. There are lots of examples around of its use. Just make sure that you follow one for VB.NET and not VB6.
 
I'm looking to launch my cmd on pressing a certain key, using a vb.net console applicaiton, but even when the applicaiton is not in focus...

I'm not using WinForms application, I'm using a console application, and when that console application detects a certain key being pressed, it'll launch the cmd.
I explained that in my first post? Maybe me wording was a bit unclear...
Sorry for the late reply.
keebs
 
Hi,

Here is an example of how to wait for a specific key press in a console application. In this case the application will continue until the Escape key is pressed.

VB.NET:
Dim NextKey As ConsoleKeyInfo
Do
  NextKey = Console.ReadKey()
  Select Case NextKey.Key
    Case ConsoleKey.A
      'write your code here
    Case ConsoleKey.B
      'write your code here
   'Case etc...
  End Select
Loop While NextKey.Key <> ConsoleKey.Escape

Hope that helps and Merry Christmas.

Cheers,

Ian
 
Thanks for your response, it is a good start, but there is still a problem.
but even when the applicaiton is not in focus...
That will only detect key presses while the application is in focus (That's the application that is selected on the screen), while I need it to detect them even when it isn't in focus.
Any suggestions?
 
Back
Top