Solved

"Communicating" with Peripherals And Virtual Keys

Posted on 2004-09-16
7
248 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

860 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