Solved

"Communicating" with Peripherals And Virtual Keys

Posted on 2004-09-16
7
247 Views
Last Modified: 2010-04-01
Is there a way to "interact" with the peripherals in a console program?  For example, switch mouse buttons...  turns caps on / off, etc?  Also, I've heard about using Virtual Keys...  is that used to basically simulate keystrokes?  

Thanks,
Tony
0
Comment
Question by:fattumsdad
  • 3
  • 2
  • 2
7 Comments
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12077119
Look at the question link below. It  should give some answers to yours as well.

http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21115369.html

Regards, Alex
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12078052
Everything I found in those answers were MFC based, I want to use console.  :)
0
 
LVL 3

Assisted Solution

by:CmdrRickHunter
CmdrRickHunter earned 250 total points
ID: 12079119
I dont see any MFC related code in the answers.  I see WindowsAPI code... are you confusing the two?
conio will contain all of the "peripheral" communications you can use in console, short of maybe some seperate apps.  The problem is that things like the caps lock key are handled by windows, so you need windows API commands to toy with them.

Its possible that DOS commands that used to edit them could be emulated by windows.  I sugest looking into how DOS used to do it, and see if windows accepts those methods.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 250 total points
ID: 12079684
>>> Everything I found in those answers were MFC based, I want to use console.  :)

Rick has it right. The SendKeys sample has an MFC demo app but the the function SendKeys() is native WinAPI.

What i found amazing is that two simple VB commands:

    objShell.AppActivate(RunAsCommand)
    objShell.Sendkeys AdminPassword

(the first starts a console job, the second sends keyinputs to that app) couldn't be imitated by C++.

Regards, Alex
0
 
LVL 3

Expert Comment

by:CmdrRickHunter
ID: 12081824
Its not really such a surprise that they cannot be imitated in C++ (without WindowsAPI).  C++ itself, remember, is just a few keywords like if, and switch.  The origional C/C++ libraries were designed with portability in mind.  They assume an absolute MINIMUM about the system.  The idea of there being other programs wanting to pretend to be the user, and faking out your program is not something of value in the origional set of libraries.

Enter the WindowsAPI, which was designed without portability in mind.  Thus if the feature should be in windows, it will be in the WindowsAPI.

As for the VB commands... all they do is call the WindowsAPI calls for you... nothing C++ with windows features can not do.
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12084254
Rick,

I see what you're saying...  and I agree totally.  I just wish that using the WindowsAPI were as simple as two VB lines :)
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12085260
>>> a surprise that they cannot be imitated in C++ (without WindowsAPI)

Rick, i couldn't reproduce the results of these VB comands using the full API. Even the SendKeys function from the link above isn't equal as it doesn't start the program by ShellExecute or CreateProcess  but by entering key inputs to the 'Run' prompt of the Windows Start menu. (the disadvantage of this is that the user may interfere wth own key inputs as you need to have long timeouts between different inputs.) Very probably, i could do it using a COM approach but it was a little bit frustrating that with native WINAPI  and hundreds of statements three is less than with 2 VB script calls,


Regards, Alex


0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question