Dim dx As New DirectX8
Dim di As DirectInput8
Dim diDEV As DirectInputDevice8
Dim diState As DIKEYBOARDSTATE
Private Sub Form_Load()
Set di = dx.DirectInputCreate()
'建立directinput对象
If Err.Number <> 0 Then
MsgBox "Direct Input初使化错误, 请检查你是否安装了DirectX8", vbApplicationModal
End
End If
Set diDEV = di.CreateDevice("GUID_SysKeyboard")
diDEV.SetCommonDataFormat DIFORMAT_KEYBOARD
diDEV.SetCooperativeLevel Me.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
Me.Show
diDEV.Acquire
tmrKey.Interval = 10
tmrKey.Enabled = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
diDEV.Unacquire
'关闭窗时释放directInputDevice8对象
End Sub
Private Sub tmrKey_Timer()
'tmrkey为时间控件,时间间隔设为10
diDEV.GetDeviceStateKeyboard diState
If diState.Key(DIK_F8)<>"" Then
Shell "sc config 服务名 start= Disabled/Enable"
End If
End Sub