By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,646 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,646 IT Pros & Developers. It's quick & easy.

How do i bind a key?

P: 37
Well, How do i bind a key in Vb6.0? and, i have searched.
Nov 19 '06 #1
Share this Question
Share on Google+
13 Replies


100+
P: 267
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

P: 37
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+
P: 267
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

P: 37
It wont work.
Nov 19 '06 #5

100+
P: 1,646
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+
P: 267
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

P: 37
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

100+
P: 1,646
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+
P: 267
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

P: 37
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+
P: 142
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

P: 37
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+
P: 267
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.