?
Solved

Keyhooks in DOS-Prompt??

Posted on 1997-12-14
13
Medium Priority
?
191 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 1600 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

801 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