How to change label.caption by pressing a specific key on the keyboard with VB?

Was the unlucky child divided by the teacher or drawn by lot?

I will give you a partially implemented code for the time being. If it's no trouble, add a few timer controls and write some similar code yourself, and it's completely realized.

First of all, this code is only for your problem. If it weren't for your problem, you'd better use API to get the global key message. If you solve your problem alone, this code is enough.

Draw a label, three timers, a button and all the default properties on the form.

Dimension i%

An event in which a key is pressed.

Private Sub command1_ keyword down (keyword is an integer, Shift is an integer).

If the key code = 65, then the timer 1. "Enabled = true" If you press a, the timer 1 starts working.

After adding the corresponding timer control, write similar code here.

End joint

An event that releases a key.

Private Sub command 1_KeyUp(KeyCode is an integer, Shift is an integer)

Timer 1. Enabled = False' stops the corresponding timer event.

Timer 3. Enabled = False' stops the related timer event.

Write similar code here.

"I = 0" timing variable is cleared.

End joint

Private subcommand 1_LostFocus ()

Command 1. "SetFocus" keeps the button in focus so that it can receive key information. It is best to use api.

End joint

Initialize the properties of each control.

Private Sub-Form _Load ()

Label 1。 Caption = "0 "

Here, after adding the corresponding label control, write similar code.

Timer 1. Interval = 1000

Timer 1. Enabled = False

Timer 2. Interval = 500

Timer 2. Enabled = False

Timer 3. Interval = 100

Timer 3. Enabled = False

Here, after adding the corresponding and related timer controls, write similar code.

End joint

Corresponding to the timer event, write similar code after adding the corresponding timer control.

Private sub-timer 1_Timer ()

I = i+ 1' Time variable accumulates every second 1, that is, the variable increases by one second.

If I = 1, timer 2. Enabled = true' If the timing variable reaches 1 sec, Timer2 starts to work.

If I = 2, the timer2.enabled = false: timer3.enabled = true' timer variable has reached two seconds. ...

End joint

Related timer events, add related timer controls and write similar code.

Private sub timer 2_Timer ()

Every 0.5 seconds label1.caption = val (label1.caption)+10' label1+10.

End joint

Private sub-timer 3_Timer ()

Every 0. 1 sec, label1.caption = val (label1.caption)+10' label1+10.

End joint

The above code only realizes pressing a, copying the code and running the test.