Solved

"Communicating" with Peripherals And Virtual Keys

Posted on 2004-09-16
7
246 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now