Results 1 to 8 of 8

Thread: [Resolved] Key Text Box

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [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

  2. #2
    Lively Member
    Join Date
    Aug 2006
    Posts
    69

    Red face Re: Key Text Box

    have u try a "keydown"....?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    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.

  4. #4
    Lively Member
    Join Date
    Aug 2006
    Posts
    69

    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

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Key Text Box

    VB Code:
    1. Dim Key_ As String
    2.  
    3. Key_ = Chr(KeyCode)
    4.  
    5. If KeyCode = 112 Then Key_ = "F1"
    6. If KeyCode = 113 Then Key_ = "F2"
    7. If KeyCode = 114 Then Key_ = "F3"
    8. If KeyCode = 115 Then Key_ = "F4"
    9. If KeyCode = 116 Then Key_ = "F5"
    10. If KeyCode = 117 Then Key_ = "F6"
    11. If KeyCode = 118 Then Key_ = "F7"
    12. If KeyCode = 119 Then Key_ = "F8"
    13. If KeyCode = 120 Then Key_ = "F9"
    14. If KeyCode = 121 Then Key_ = "F10"
    15.  
    16. If KeyCode >= 112 Then If KeyCode <= 121 Then GoTo F_Key
    17.  
    18. If KeyCode <= 40 Then Exit Sub
    19. If Shift = 0 Then Exit Sub
    20.  
    21. F_Key:
    22.  
    23. If Shift = 1 Then Text1.Text = "Shift+" & Key_
    24. If Shift = 2 Then Text1.Text = "Ctrl+" & Key_
    25. If Shift = 3 Then Text1.Text = "Ctrl+Shift+" & Key_
    26. If Shift = 4 Then Text1.Text = "Alt+" & Key_
    27. If Shift = 5 Then Text1.Text = "Alt+Shift+" & Key_
    28. If Shift = 6 Then Text1.Text = "Ctrl+Alt+" & Key_
    29. 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!

  6. #6
    Lively Member
    Join Date
    Aug 2006
    Posts
    69

    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....

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: [Resolved] Key Text Box

    Yep, thanks for that!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width