#TouchKeyboard制御
Const WM_SYSCOMMAND As Integer = &H112
Const SC_CLOSE As Integer = &HF060
Const AlphanumericHalfWidth As Integer = 40
Const TelephoneNumber As Integer = 32
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function SendMessage(ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("msctf.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function SetInputScope(ByVal hwnd As IntPtr, ByVal inputscope As IntPtr) As IntPtr
End Function
''' <summary>
''' ソフトウェアキーボードを起動
''' </summary>
Private Sub OpenKeyboard()
Process.Start("c:\program files\common files\microsoft shared\ink\tabtip.exe")
End Sub
''' <summary>
''' ソフトウェアキーボードを終了
''' </summary>
Private Sub CloseKeyboard()
'ソフトウェアキーボードのウィンドウを探す
Dim hWnd As IntPtr = FindWindow("IPTip_Main_Window", "")
'見つけたら閉じるメッセージを送信
If hWnd <> IntPtr.Zero Then
Call SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0)
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim hwnd As IntPtr
'TextBox1上touchkeyboardのタイプを数値モードに
hwnd = Me.TextBox1.Handle
SetInputScope(hwnd, TelephoneNumber )
End Sub
Private Sub TextBox1_GotFocus(sender As Object, e As EventArgs) Handles TextBox1.GotFocus
OpenKeyboard()
End Sub
*~~TABLETTIPLibがWindows7.1 SDK?にあるらしい。~~探してみたが見つからない。TabTip.exeを参照に追加するといった記述を見つけたがWindows8のTabTip.exeではできないみたいだ。
Dim TabTIP As TABLETTIPLib.UIHostClass = New TABLETTIPLib.UIHostClass()
TabTIP.ShowWnd(True) '消すときはFalse
- touchkeyboardが画面幅いっぱいだと表示されるときにフォームが
小さくされてしまうが、戻すタイミング(touchkeyboardが消えるタイミング)
はどうしたらわかるのだろうか。
#物理キーボード検出
Public Enum RawInputDeviceType As UInteger
MOUSE = 0
KEYBOARD = 1
HID = 2
End Enum
<StructLayout(LayoutKind.Sequential)> _
Public Structure RAWINPUTDEVICELIST
Public hDevice As IntPtr
Public dwType As IntPtr
End Structure
<DllImport("user32.dll", CharSet:=CharSet.Auto,
EntryPOint:="GetRawInputDeviceList", SetLastError:=True)> _
Private Shared Function GetRawInputDeviceList(ByVal pRawInputDeviceList As _
IntPtr, ByRef puiNumDevices As IntPtr, ByVal cbSize As IntPtr) As IntPtr
End Function
Private _nummouse As Integer = 0
Private _numkeyboard As Integer = 0
Private _numhid As Integer = 0
Public Sub New()
Dim devlist As RAWINPUTDEVICELIST
Dim buf As IntPtr
Dim i As Integer
Dim bufsz As Integer
Dim dsz As Integer
Dim ret As Integer
dsz = Marshal.SizeOf(GetType(RAWINPUTDEVICELIST))
ret = GetRawInputDeviceList(IntPtr.Zero, bufsz, dsz)
buf = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(RAWINPUTDEVICELIST)) * bufsz)
ret = GetRawInputDeviceList(buf, bufsz, dsz)
For i = 0 To ret - 1
Dim p As IntPtr
p = New IntPtr(buf.ToInt32 + Marshal.SizeOf(GetType(RAWINPUTDEVICELIST)) * i)
devlist = CType(Marshal.PtrToStructure(p, GetType(RAWINPUTDEVICELIST)), RAWINPUTDEVICELIST)
If (devlist.dwType = phykey.RawInputDeviceType.KEYBOARD) Then
_numkeyboard = _numkeyboard + 1
End If
Next
Marshal.FreeHGlobal(buf)
End Sub
ノーパソで試したところ1が取れた。タブレットはどうなるんだろ。
USBキーボードやBTキーボードだとHIDになるのかしら??
タブレットで試したところキーボードない状態なのに2が返ってきたのでこれではダメそう。
Detect keyboard presence in Windows 8 desktop program
なんかまんまの書き込みを見つけたのでこれもやってみるかな。
#画面ローテーション
解像度の変更イベントで拾えるらしい。