Solved

Keyhooks in DOS-Prompt??

Posted on 1997-12-14
13
188 Views
Last Modified: 2013-12-03
How can I receive keystrokes from a DOS-Prompt or a DOS-program with my Visual Basic 5.0 program.
Is there an API-Call or something like this?? I used the API Message Functions to recieve the keystrokes, but it doesen't work. How can I find out, witch key was pressed in the DOS prompt or the DOS program??? Is it possible??
0
Comment
Question by:BenLee
[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
  • 8
  • 4
13 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 400 total points
ID: 1409536
Answer comming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1409537
You should be able to set a hook on the DOS proccess using SetWidowsHookEx().  You would use

SetWindowsHookEx(WH_KEYBOARD,HookProc,hInstance,ThreadID);

Thread ID should be the thread for the DOS process you are hooking.  I'm not sure how you get that thread ID, because I'm not sure how you know the DOS process you are interested.  Hopefully you already have an answer to this, if not, explain how you know which DOS prompt you want to hook.

the HookProc should be declared as

LRESULT CALLBACK HookProc(int code,WPARAM wParam,LPARAM lParam)
{
   if (code < 0)
      return CallNextHookEx(code,wParam,lParam);
   if  (code = HC_ACTION)
      // look at virtual code in wParam and repeat count in lParam.
   return 1;
}
0
 
LVL 22

Expert Comment

by:nietod
ID: 1409538
Woops! You asked for visual basic and I gave you C.  Well, the idea should be the same, you still need to use the SetWindowsHookEx() procedure.  You just have to use it in basic Visual basic syntax.
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 11

Expert Comment

by:alexo
ID: 1409539
nietod, have you actually tested your proposed solution?

There was a similar question by somebody not long ago (sorry, forgot the reference) and the combined wizdom of the experts reached the conclusion that WH_KEYBOARD hooks do not work for command-line windows under NT.

I'd be happy to be proven wrong.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1409540
No.  I guess I didn't make it clear enough with the word "should", but I've never tried this.  From what I've read about in Microsoft's documentation about input is handled, it should work.  But their documentation is often simplified or just plain wrong.


0
 
LVL 11

Expert Comment

by:alexo
ID: 1409541
Found the reference (qid=8630028164).

tcola asked:

--- begin quote ---

Right now I have a program in Visual C++ that will execute certain commands after X minutes a system idle. The system is considered "idle" by my program when no keyboard or mouse activity is occuring.

The program works fine in pure windows, but when users sit in an MS-DOS Box for these X amount of minutes my windows program will not detect any mouse/keyboard activity (even if someone is pounding the keys).

Right now, I set a hook to the keyboard and mouse through a dll.
                   
I want my program to detect any mouse/keyboard activity regardless of if the user is typing into the MS-DOS Box or not.

--- end quote ---

I suggested to use a VxD for Win95.

Frankly, I'm curious myself.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1409542
The hook in that case is a system wide hook (not a hook for a specific process).  Perhaps a hook for a specific DOS process will work.  Yeah, its a long shot, but its easier to test than to write a VxD.  
0
 
LVL 11

Expert Comment

by:alexo
ID: 1409543
Why should be there be a difference?  The underlying mechanism for system-wide hooks and per-thread hooks seems to be the same.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1409544
Why?  Mostly, wishful thinking.  It is possible that for a system-wide hook, the operating system checks the process to see if it is a DOS process and, if so, does not pass it to the hook procedure assuming that windows applications aren't interested in  DOS applications.  However, given a hook for a specific process, it might guess that the hooking program obviously wants to hook the specified program regardless of whethor or not it is a DOS program so it might call the hook procedure.

Sounds logical?  Yeah, I know.  If I could reject my own answer, I would have already.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1409545
But then we would lose the forum for exchanging ideas :-)

BTW, strange that we haven't heard from BenLee.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1409546
I noticed that too.  For 400 points you would think he is desperate for an answer.  For a 50 question I check for answers every hour, but I'm cheap.
0
 

Author Comment

by:BenLee
ID: 1409547
I think it should work!! Thanks nietod!!
0
 
LVL 22

Expert Comment

by:nietod
ID: 1409548
You should try it BEFORE accepting my answer.  It might not work and you are out 400 points!  If it doesn't work I would be happy to try to help you, but you would do better with help from more experts.  

If it doesn't work, and if the experts exchange customer service people can arrange it, I would be willing to give the points back to have the question reopened.  (Not that I'm eager to loose the points, but I'm sure you want a working solution.)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

691 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