Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

"Communicating" with Peripherals And Virtual Keys

Posted on 2004-09-16
7
Medium Priority
?
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 1000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

715 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