[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Keyhooks in DOS-Prompt??

Posted on 1997-12-14
13
Medium Priority
?
192 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

649 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