How do i bind a key?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Blurbint
    New Member
    • Nov 2006
    • 37

    How do i bind a key?

    Well, How do i bind a key in Vb6.0? and, i have searched.
  • albertw
    Contributor
    • Oct 2006
    • 267

    #2
    Originally posted by Blurbint
    Well, How do i bind a key in Vb6.0? and, i have searched.
    hi

    what key did you have in mind, and bind to what?

    Comment

    • Blurbint
      New Member
      • Nov 2006
      • 37

      #3
      Originally posted by albertw
      hi

      what key did you have in mind, and bind to what?
      Lets say, W to
      Code:
      form1.Backcolor = qbcolor (15)
      ?

      Comment

      • albertw
        Contributor
        • Oct 2006
        • 267

        #4
        Originally posted by Blurbint
        Lets say, W to
        Code:
        form1.Backcolor = qbcolor (15)
        ?
        hi
        tak e.g:

        Code:
        Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyF2 Then Form1.BackColor = QBColor(15)
        End Sub
        you may chose any key (see MSDN help on KeyDown)

        Comment

        • Blurbint
          New Member
          • Nov 2006
          • 37

          #5
          It wont work.

          Comment

          • willakawill
            Top Contributor
            • Oct 2006
            • 1646

            #6
            Originally posted by Blurbint
            It wont work.
            It will work if you apply the code to the first control that receives the focus when you start your app. This will be the control with a tab index of 0

            Comment

            • albertw
              Contributor
              • Oct 2006
              • 267

              #7
              Originally posted by willakawill
              It will work if you apply the code to the first control that receives the focus when you start your app. This will be the control with a tab index of 0
              hi
              of course should it be

              Private Sub Form_KeyDown(Ke yCode As Integer, Shift As Integer)
              If KeyCode = vbKeyW Then Form1.BackColor = QBColor(15)
              End Sub

              how stupid to assign F2 to the color white ... :(

              Comment

              • Blurbint
                New Member
                • Nov 2006
                • 37

                #8
                Originally posted by willakawill
                It will work if you apply the code to the first control that receives the focus when you start your app. This will be the control with a tab index of 0
                I don't get it, would you explain it a little bit easier for me ,as i am new to vb.
                And Albert, it still doesnt work.

                Comment

                • willakawill
                  Top Contributor
                  • Oct 2006
                  • 1646

                  #9
                  Originally posted by Blurbint
                  I don't get it, would you explain it a little bit easier for me ,as i am new to vb.
                  And Albert, it still doesnt work.
                  In design view set the KeyPreview property of your form to true
                  Then Albert's code will work

                  Comment

                  • albertw
                    Contributor
                    • Oct 2006
                    • 267

                    #10
                    Originally posted by willakawill
                    In design view set the KeyPreview property of your form to true
                    Then Albert's code will work
                    sry, will explain ...

                    Create a form (usually the name will be Form1 if you don't change it)
                    then doubleclick in your newly made form --> a new (blank) screen will open with statement Sub Form_Load()
                    in righthand top corner you find a dropdown listbox -- select here:
                    KeyDown
                    Now a new sub will be opened called Form_KeyDown(.. ..
                    paste the previous code inhere
                    beware not to use sub Form_KeyDown and End Sub twice
                    now, when you start your project (F5) the program will rub, doing NOTHING untill you press the key W, then your form should turn pale

                    Comment

                    • Blurbint
                      New Member
                      • Nov 2006
                      • 37

                      #11
                      Originally posted by albertw
                      sry, will explain ...

                      Create a form (usually the name will be Form1 if you don't change it)
                      then doubleclick in your newly made form --> a new (blank) screen will open with statement Sub Form_Load()
                      in righthand top corner you find a dropdown listbox -- select here:
                      KeyDown
                      Now a new sub will be opened called Form_KeyDown(.. ..
                      paste the previous code inhere
                      beware not to use sub Form_KeyDown and End Sub twice
                      now, when you start your project (F5) the program will rub, doing NOTHING untill you press the key W, then your form should turn pale
                      ah, now it works. But how do i add more bindings?

                      Comment

                      • sivadhas2006
                        New Member
                        • Nov 2006
                        • 142

                        #12
                        Originally posted by Blurbint
                        ah, now it works. But how do i add more bindings?
                        Hi,

                        To add more key bindings, you can do like this...

                        Code:
                        Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
                        Select Case KeyCode
                        	 Case vbKeyW
                        		 BackColor = QBColor(15)
                        	 Case vbKeyF
                        		 ForeColor = QBColor(5)
                        	 Case vbKeyM
                        		 MsgBox "Added more keys...", vbInformation
                        End Select
                        End Sub
                        Regards,
                        M.Sivadhas.

                        Comment

                        • Blurbint
                          New Member
                          • Nov 2006
                          • 37

                          #13
                          THanks, but just one more question, how do i deselect a thing? Like if i would wanna type in something, then press enter too remove it. But now it select the text box and nothing happens when you press enter, except the ding. so, now i want it too deselect the text box when i press enter. Hope you understand.

                          Comment

                          • albertw
                            Contributor
                            • Oct 2006
                            • 267

                            #14
                            Originally posted by Blurbint
                            THanks, but just one more question, how do i deselect a thing? Like if i would wanna type in something, then press enter too remove it. But now it select the text box and nothing happens when you press enter, except the ding. so, now i want it too deselect the text box when i press enter. Hope you understand.
                            hi

                            about the same procedure
                            select your object
                            doubleclick
                            then select in the right upper corner e.g: click / doubleclick or KEYDOWN

                            Code:
                            Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
                            '--- clear text when hitting Enter
                            If KeyCode = vbKeyReturn Then Text1.Text = vbNullString
                            '--- clear text when hitting Backspace
                            If KeyCode = vbKeyBack Then Text1.Text = vbNullString
                            End Sub

                            Comment

                            Working...