Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

User input without textbox 2

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
0
0
US
How can a program receive input (from the keyboard) if a textbox doesn't have focus? Say if a program is going to lock up the computer (for windows 98 or whatever) as a security setting, and it'll only receive keyboard inputs and it waits for the password to be typed to unlock the pc so the user can work again.

I've seen it before, I just don't know how to do it. -Ovatvvon :-Q
 
you could put a textbox in, set the focus to that textbox when it "Locks up"
Change the colour of the textbox to match the background,
take the borders off of the text box
and make the font colour the same colour as the background.

Now the textbox is there, you just don't see it and you don't see anything typed in it.
 
Is there a way to do it without the textbox there? I'd like there to be graphics...different options for backgrounds/images. But I'd still like it to be able to receive input, without the textbox.

Any ideas? -Ovatvvon :-Q
 
try this

Option Explicit
Private str As String


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
str = str & Chr(KeyCode)
Cls
Print str
End Sub

Private Sub Form_Load()
AutoRedraw = True
End Sub


All the best.... Praveen Menon
 
Try this:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Static strpassword
Select Case KeyCode
Case 13
Debug.Print strpassword
strpassword = ""
'enable your controls here
Case Else
strpassword = strpassword & Chr(KeyCode)
End Select
End Sub
Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
johnwm, you're worked more how I wanted it too. In fact, it's almost just how I need it. However, one problem remains. If alt-tab was hit, or something to that nature that would cause focus to move away from the program, it stops taking inputs. Can it be made so it takes inputs even if it looses focus? (by entering it in another procedure type or somthing like that?) -Ovatvvon :-Q
 
For that, you will have to hook the Keyboard using a DLL. If it is a trojan that you are planning to make, it can be made only by hooking the keyboard. Many of the developer sites have the DLLs and sample projects available, search google for "Free VB Soruce" and then search on the sites for "Key Logger".

All the best. Praveen Menon
 
For that, you will have to hook the Keyboard using a DLL. If it is a spy app that you are planning to make, it can be made only by hooking the keyboard. Many of the developer sites have the DLLs and sample projects available, search google for "Free VB Soruce" and then search on the sites for "Key Logger".

All the best. Praveen Menon
 
There's plenty of examples in this very forum on how to hook the keyboard. In particular there are versions that don't require a DLL...
 
What do you mean "hook the keyboard"? -Ovatvvon :-Q
 
I believe they mean "hook into the keyboard" by watching the actual keyboard input, more or less non-stop. That means you read the input even when they aren't in your program, and in my opinion thats very unethical. Brad,
Hey! email me any time! Bradsvb@yahoo.com
 
Simply and in brief (i.e this is not a technical description), a hook is a function you can create as part of a dll or your application to monitor the 'goings on' inside the windows operating system. The idea is to write a function that is called every time a certain event in windows occurs - for example when a user presses a key on the keyboard or moves the mouse

As an aside, a crowbar can be used to break into houses, which might be considered unethical. A crowbar in itself, however, is not unethical.
 
Considering these are work pc's dealing with information that should not be passed outside the offices, I will add to that analogy...

While using a crow bar to break into a house may be unethical, you may have overlooked the possibility that the house is on fire and ther are 2 children hiding in the closet inside a locked room. Now is it unethical to break into the house for a greater cause? Especially when the owners (/ operators) of the house know well and clear that their property will be broken into to secure the valuables? Enough said I hope.

So back to the subject... It works fine when the form has focus however, how could the code above hook the keyboard when the form does not have focus? That's the problem I'm running into. -Ovatvvon :-Q
 
Go back to my original message and you will see that I mention that we've been down this road before. Just do a keyword search and you should find the relevant threads with full working code.
 
strongm,
The only thing I can find while using a keyword search for keyboard hooks is regarding C++. The VB stuff that had anything to do with it didn't really help to explain how to do it. Perhaps I missed it though? Is there a specific thread you knew of?

p.s. Thank you very much for all the help so far! -Ovatvvon :-Q
 
Yup, traditionally the solution involves at least one small DLL in C++.

However, here's the thread where I first showed how to do this under NT4/W2000 using only VB and API calls: thread222-118564

I also provided code for a solution that works under W95/98/Me and NT4/W2000/XP in the last couple of weeks - but the thread seems to have vanished. I'll dig out my copy of it again, and repost.
 
thank you....I'll go check out that thread. -Ovatvvon :-Q
 
strongm,
I know this is gonna sound stupid, but which variable actually stores the keycode value in the script you posted? -Ovatvvon :-Q
 
lol, nevermind, I just didn't read it carefully enough. I see it.

This is perfect. If you have the code that works with 98 too, that would be even better, but this is great! -Ovatvvon :-Q
 
I doesn't seam to be able to tell the difference between small and caps letters though. And I can't get when the numbers are shifted for symbols.

How can I get that to work? -Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top