|
-
Mar 23rd, 2008, 04:46 AM
#1
Thread Starter
New Member
push to show a msg
hi all i would like to make a project where i would have to hold down any button
down on the keyboard or even mouse down an it will show the msg on the form
and when i let go of the button the msg will not show
any ideas on how i can go about this
thanks
-
Mar 23rd, 2008, 04:53 AM
#2
Re: push to show a msg
Create a project and on the Form Draw a Frame (Frame1) set it's visible property to False and blank out its Caption. Inside the Frame draw a Label and set its Caption property to whatever message you want displayed. Set the KeyPreview property of the Form to True. Copy and paste the code below into the Declaration Section of the Form and run it
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Frame1.Visible = True
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Frame1.Visible = False
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Frame1.Visible = True
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Frame1.Visible = False
End Sub
Note that the Mouse down and up only work on the area of the Form that has no controls on it. The Key down and up should work everywhere on the Form
-
Mar 23rd, 2008, 05:03 AM
#3
Thread Starter
New Member
Re: push to show a msg
nice thank you ,is it possible to have lets say i want to choose which button i want to use for instance i want to use Q or A button for it to work that would be greatfull
and thanks for the quik responce
-
Mar 23rd, 2008, 05:16 AM
#4
Re: push to show a msg
Something like this
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyA Then
Frame1.Visible = True
End If
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyA Then
Frame1.Visible = False
End If
End Sub
-
Mar 23rd, 2008, 06:27 AM
#5
Thread Starter
New Member
Re: push to show a msg
thank you
much appreciated
-
Mar 25th, 2008, 01:38 AM
#6
Thread Starter
New Member
Re: push to show a msg
hi again
Ive been playing around with the code and been trying to
have a the vb key assigned in text box ,like i would like to change what button I want to press or even a combo box an have the key code constance in the combo box
something like that
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKey & text1.text Then
Frame1.Visible = True
End If
End Sub
OR
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
vbkey = Form2.Text1.Text
If KeyCode = Form2.Text1.Text Then
Frame1.Visible = True
End If
End Sub
instead of vbkeyA the "A" would be in the textbox an i could change it to what ever i like
any help would be great
Last edited by whiskydrinka; Mar 25th, 2008 at 01:48 AM.
-
Mar 25th, 2008, 02:34 AM
#7
Re: push to show a msg
There may be better approaches but I'd define a common boolean variable to indicate if the Key has yet been defined, when it has set the boolean and test it in the Form_KeyDown event. If you're only going to use alphanumeric keys it shouldn't be too difficult since their KeyCodes are the same as their ASCII codes. Something for you to play with.
Code:
Private boKeySet As Boolean
Private intKey As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If boKeySet = True Then
If KeyCode = intKey Then
Frame1.Visible = True
End If
End If
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If boKeySet = True Then
If KeyCode = intKey Then
Frame1.Visible = False
End If
End If
End Sub
Private Sub txtKey_KeyPress(KeyAscii As Integer)
'
' Check if the Key has been set
'
If boKeySet = False Then
'
' No, then check that an alphanumeric key has been pressed
' 48 = "0", 57 = "9"
' 65 = "A", 90 = "Z"
' 97 = "a", 122 = "z"
'
If (KeyAscii >= 48 And KeyAscii <= 57) Or _
(KeyAscii >= 65 And KeyAscii <= 90) Or _
(KeyAscii >= 97 And KeyAscii <= 122) Then
'
' Valid key has been pressed
'
If KeyAscii >= 97 Then
'
' Since the KeyCode will return the same value whether "a" or "A"
' is pressed (eg 65), our intKey must always contain the uppercase
' value. Alternatively, and on reflection, better, we could check the
' value of Shift in the KeyDown and KeyUp events.
' Perhaps I'll leave that up to you. (Lazy me)
'
intKey = KeyAscii - (97 - 65)
Else
intKey = KeyAscii
End If
boKeySet = True
Else
'
' Invalid key pressed, beep to alert the user
'
Beep
End If
Else '
'
' After the key has been pressed ignore
' additional characters entered into txtKey
'
KeyAscii = 0
End If
End Sub
Then
[code]
Last edited by Doogle; Mar 25th, 2008 at 02:39 AM.
-
Mar 25th, 2008, 03:40 AM
#8
Thread Starter
New Member
Re: push to show a msg
private sub thanks_click ()
thanks for that im trying to add the keyascii into a combobox looking good so far still playing around with it ,Ive even used the keytext.locked = true an false
so i can use any keyacsii an lock it so it dont keep typing it in the textbox
thanks heaps
end sub
Last edited by whiskydrinka; Mar 25th, 2008 at 03:44 AM.
-
Mar 25th, 2008, 08:10 AM
#9
Re: push to show a msg
Does this resolve your problem or do you still have questions?
-
Mar 26th, 2008, 03:44 AM
#10
Thread Starter
New Member
Re: push to show a msg
 Originally Posted by Hack
Does this resolve your problem or do you still have questions?
thanks doogle
Last edited by whiskydrinka; Apr 11th, 2008 at 11:02 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|