467,881 Members | 1,180 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,881 developers. It's quick & easy.

How do i bind a key?

Well, How do i bind a key in Vb6.0? and, i have searched.
Nov 19 '06 #1
  • viewed: 5115
Share:
13 Replies
100+
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?
Nov 19 '06 #2
hi

what key did you have in mind, and bind to what?
Lets say, W to
Expand|Select|Wrap|Line Numbers
  1. form1.Backcolor = qbcolor (15)
?
Nov 19 '06 #3
100+
Lets say, W to
Expand|Select|Wrap|Line Numbers
  1. form1.Backcolor = qbcolor (15)
?
hi
tak e.g:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  2. If KeyCode = vbKeyF2 Then Form1.BackColor = QBColor(15)
  3. End Sub
  4.  
you may chose any key (see MSDN help on KeyDown)
Nov 19 '06 #4
It wont work.
Nov 19 '06 #5
1GB
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
Nov 19 '06 #6
100+
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(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyW Then Form1.BackColor = QBColor(15)
End Sub

how stupid to assign F2 to the color white ... :(
Nov 19 '06 #7
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.
Nov 20 '06 #8
1GB
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
Nov 20 '06 #9
100+
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
Nov 20 '06 #10
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?
Nov 20 '06 #11
sivadhas2006
100+
ah, now it works. But how do i add more bindings?
Hi,

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

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  2. Select Case KeyCode
  3.      Case vbKeyW
  4.          BackColor = QBColor(15)
  5.      Case vbKeyF
  6.          ForeColor = QBColor(5)
  7.      Case vbKeyM
  8.          MsgBox "Added more keys...", vbInformation
  9. End Select
  10. End Sub
  11.  
Regards,
M.Sivadhas.
Nov 21 '06 #12
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.
Nov 21 '06 #13
100+
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
  3. '--- clear text when hitting Enter
  4. If KeyCode = vbKeyReturn Then Text1.Text = vbNullString
  5. '--- clear text when hitting Backspace
  6. If KeyCode = vbKeyBack Then Text1.Text = vbNullString
  7. End Sub
  8.  
  9.  
Nov 21 '06 #14

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Clarence Gardner | last post: by
1 post views Thread by Achille Carette | last post: by
2 posts views Thread by P G | last post: by
4 posts views Thread by Arturo Cuebas | last post: by
2 posts views Thread by IndyStef | last post: by
reply views Thread by teclioness | last post: by
1 post views Thread by Tigera | last post: by
6 posts views Thread by crack.the.hack | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.