Solved

"Communicating" with Peripherals And Virtual Keys

Posted on 2004-09-16
7
244 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 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.

706 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

17 Experts available now in Live!

Get 1:1 Help Now