keystroke action

chewy

SuperNintendo Chalmers
Local time
Today, 05:46
Joined
Mar 8, 2002
Messages
581
How would I invoke a function or a call..just like if a user clicked a button, I want to know how if say they type in "test" I want to be able to dispay a message box or something.

Thanks
 
Hi chewy,

go into the properties of your text box. On the "On change" event, put something like this in your code:

Private Sub Text0_Change()
If txtTextfield.Text = "test" Then
MsgBox "test was typed!!!!"
End If

Hope that helps!

-Sean
 
The thing is I dont want it typed in a text box. What I want is if nothing has the focus I want to be able to type "test" and I want to be able to do some code. Kind of like cheat codes in games where a special combination of keystrokes unlocks things...or Easter Eggs in programs and Windows
 
Chewy:

Here's an idea:

Create a small retangle on your form and make it invisible by setting the Border and Background to "Transparent" and the color to that of your form.

Then add code to it on the On Double Click event.

If you hide it in the bottom corner of your form (somewhere only you know about) the chances that someone else will Double click it are pretty slim.

Just a quick idea.
 
this really is just out of curiousity...I have been thinking about it for a while. What I actually want to do is when the user types in some special word I want it to bring up a message box with my name and other information. It is really an about box but I dont want it to be publicly known
 
no one else had any thoughts on this?
 
chewy,

Check out the KeyPreview property for the Form. You'd use this in conjunction with:

1) Module-level string variable (to hold a running concatenation of keystroke characters)

2) An 'If/Then' comparison of that string variable with your special word in the KeyDown event for your Form

That should give a framework you can use to work out from here.

HTH,
John
 
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
    Static strEasterEgg As String
    
    strEasterEgg = strEasterEgg & Chr(KeyAscii)
    
    If InStr(1, strEasterEgg, "Test") Then
        MsgBox "Hello, this is by Chewy!"
    End If
    
End Sub
 
Mile-O-Phile youve done it again! Works good except after you get the message, after you press any key it gives you the message. I just added a clear string line

Private Sub Form_KeyPress(KeyAscii As Integer)
Static strEasterEgg As String

strEasterEgg = strEasterEgg & Chr(KeyAscii)

If InStr(1, strEasterEgg, "Test") Then
MsgBox "Hello, this is by Chewy!"
strEasterEgg = ""
End If

End Sub
 
Good point, a small oversight on my part.
 
now how would I make a mouse click reset easter egg? I tried

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

strEasterEgg = ""

End Sub
 
I got the mouse click tp reset strEasterEgg but the click only works in the bottom of the form. Anyone know why?
 
Rather than the form's OnClick event, put it in the Detail_Click() event
 
good idea. I put in in the on_Click and Detail_Click then it gets it no matter what. Thanks everyone!
 

Users who are viewing this thread

Back
Top Bottom