|
-
Aug 15th, 2006, 04:42 AM
#1
Thread Starter
Fanatic Member
[Resolved] Key Text Box
Hmmm, i'm making a program that will take screen shots.
I want to assign a text box to show what key(s) to press to take the screen shot. I also want it to be able to be changed by the user.
For example, when the text box has focus and the user is holding down Ctrl+S then the text box will say Ctrl+S. If if the user if holding down Shift+Ctrl+D then the text box will say that.
I'm going to be using a system wide keyboard hook to watch for the keypresses (to raise the screen shot event).
If anyone knows how to do this, or a better way to do this please reply here. All my effors have failed so far, such as getting the ASCII from the text box.
Last edited by Hack; Aug 15th, 2006 at 06:03 AM.
Reason: Added green "resolved" checkmark Last edited by Asharon : Today at 02:16 AM
-
Aug 15th, 2006, 04:48 AM
#2
Lively Member
Re: Key Text Box
have u try a "keydown"....?
-
Aug 15th, 2006, 04:58 AM
#3
Thread Starter
Fanatic Member
Re: Key Text Box
Yes, i have tried it. But the numbers are wierd:
Ctrl+Z = KeyCode=90, Shift=2
Z+Ctrl = KeyCode=17, Shift=2
Ctrl+Shift = KeyCode=16, Shift=3
Shift+Ctrl = KeyCode=17, Shift=3
Ctrl+Shift+Z = KeyCode=90, Shift=3
Shift+Ctrl+Z = KeyCode=90, Shift=3
How does one make sense of that? They are the results i got.
-
Aug 15th, 2006, 05:07 AM
#4
Lively Member
Re: Key Text Box
try this vb code
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim vCtrlDown
Ctrldown = (Shift And vbCtrlMask) > 0
'When u press Ctrl button
If Ctrldown Then
Label1.Caption = "CTRL+" & Chr(KeyCode)
End If
End Sub
-
Aug 15th, 2006, 05:24 AM
#5
Thread Starter
Fanatic Member
Re: Key Text Box
VB Code:
Dim Key_ As String
Key_ = Chr(KeyCode)
If KeyCode = 112 Then Key_ = "F1"
If KeyCode = 113 Then Key_ = "F2"
If KeyCode = 114 Then Key_ = "F3"
If KeyCode = 115 Then Key_ = "F4"
If KeyCode = 116 Then Key_ = "F5"
If KeyCode = 117 Then Key_ = "F6"
If KeyCode = 118 Then Key_ = "F7"
If KeyCode = 119 Then Key_ = "F8"
If KeyCode = 120 Then Key_ = "F9"
If KeyCode = 121 Then Key_ = "F10"
If KeyCode >= 112 Then If KeyCode <= 121 Then GoTo F_Key
If KeyCode <= 40 Then Exit Sub
If Shift = 0 Then Exit Sub
F_Key:
If Shift = 1 Then Text1.Text = "Shift+" & Key_
If Shift = 2 Then Text1.Text = "Ctrl+" & Key_
If Shift = 3 Then Text1.Text = "Ctrl+Shift+" & Key_
If Shift = 4 Then Text1.Text = "Alt+" & Key_
If Shift = 5 Then Text1.Text = "Alt+Shift+" & Key_
If Shift = 6 Then Text1.Text = "Ctrl+Alt+" & Key_
If Shift = 7 Then Text1.Text = "Ctrl+Alt+Shift+" & Key_
That is working fine as far as i can tell. Thanks for your code, it allowed me to see how this actually works. If you have a better way please post it!
-
Aug 15th, 2006, 05:30 AM
#6
Lively Member
Re: [Resolved] Key Text Box
maybe it's better if u know vb constant value for keycode, like:
if keycode = vbKeyF1 then .......'when you press F1 button
if keycode = vbKeyF2 then .......'when you press F2 button
if keycode = vbKeyEscape then .......'when you press ESC button
if keycode = vbKeySpace then......'when you press SPACE BAR button
and so on....
-
Aug 15th, 2006, 09:27 AM
#7
Re: [Resolved] Key Text Box
Use the help file - look for keycode constants.
The shift, ctrl and alt keys work like this:
vbShiftMask = 1
VbCtrlMask = 2
VbAltMask = 4
So if you hold alt and shift keys, the Shift value would be 4 + 1 = 5.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Aug 15th, 2006, 10:24 AM
#8
Thread Starter
Fanatic Member
Re: [Resolved] Key Text Box
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
|