Private Sub Text1_KeyDown(KeyCode As Integer, ShiftAs Integer)
Const Alt=4
Const Key_F2=&H71
altdown%=(ShiftAnd Alt)> 0
f2down%=(KeyCode=Key_F2)
If altdown% And f2down%Then
Text1.Text="abl"
End If
EndSub
(Shift And Alt)> 0是关系运算,结果为True或False,当shift=4时,shift and alt=4,大于0,则altdown%=true=-1,否则altdown%=false=0。这段代码的意思是当text1获得焦点时,按下alt键不放,同时按下f2键,text1内容即为abl
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Const Alt=4定义二个常量,分别是 二个键的代码
Const Key_F2=&H71
altdown%=(Shift And Alt)> 0 控制键与 ALT 进行 AND 位运算,然后判断是否〉0,
f2down%=(KeyCode=Key_F2) 是否按下了F2
If altdown% And f2down%Then 逻辑运算,是否全是真
Text1.Text="abl"
End If
EndSub