2015-07-10 59 views

回答

0

如果你的意思是,如果你真的键入这一切都取决于你如何发送“W”的程序.... ,您可以使用文本框的_KeyDown_KeyUp_KeyPress事件。 。

Private Sub Textbox_KeyPress(KeyAscii As Integer) 
    If KeyAscii = Asc("W") then Call MsgBox("Yes 'W' pressed") 
End Sub 

Private Sub TextBox_KeyDown(KeyCode As Integer, Shift As Integer) 
    If KeyCode = vbKeyW And ((Shift And vbShiftMask) = vbShiftMask) Then Call MsgBox("Yes 'W' pressed") 
End Sub 

,或者您需要使用_Change事件,这ofcourse是你需要存储以前的文本,并将其与当前的文本进行比较,看是否有更多的工作来追踪变化'W'已被添加。但是你必须考虑到人们可能会粘贴多个字母。

Private Sub TextBox_Change() 
    If Instr(TextBox.Text, "W")>0 Then 
    If Instr(TextBox.Tag, "W") = 0 Then 
     Call MsgBox("Yep 'W' added") 
    Else 
    'run down the Text along with the Tag and see if a 'W' is present at the same location 
    End If 
    End If 
    TextBox.Tag = TextBox.Text 
End Sub