|
■No48604 (Hongliang さん) に返信
> 「PreProcessMessage または PreFilterMessage」の中で、「m.Msg が WM_KEYDOWN で WParam が VK_PROCESSKEY のとき」に、「Win32API の ImmGetVirtualKey 関数を使用する」んです。
書いてみました。
Public Class Form1
Private WithEvents TextBox1 As Sample
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
TextBox1 = New Sample()
Controls.Add(TextBox1)
End Sub
Private Sub TextBox1_VirtualKeyPressed(ByVal sender As Object, ByVal e As KeyEventArgs) Handles TextBox1.VirtualKeyPressed
Debug.Print(e.KeyData.ToString())
End Sub
Private Class Sample
Inherits TextBox
Private Declare Function ImmGetVirtualKey Lib "imm32" (ByVal hwnd As IntPtr) As Keys
Public Event VirtualKeyPressed As KeyEventHandler
Public Overrides Function PreProcessMessage(ByRef msg As Message) As Boolean
Const WM_KEYDOWN As Integer = &H100
If msg.Msg = WM_KEYDOWN AndAlso msg.WParam = CType(Keys.ProcessKey, IntPtr) Then
RaiseEvent VirtualKeyPressed(Me, New KeyEventArgs(ImmGetVirtualKey(Handle)))
End If
Return MyBase.PreProcessMessage(msg)
End Function
End Class
End Class
|