感谢。问题已经解决,源码如下:
#include <date.au3>
#include <mysql.au3>
#include <file.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <RawInput.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <array.au3>
$sUsername=""
$sPassword=""
$sServer=""
$sDatabase="doa"
$sdriver="{MySQL ODBC 5.3 ANSI Driver}"
Local $array[5][4]
Dim $file
Global $aa
TrayTip("数据库已连接","数据库已连接",15,1)
ConsoleWrite(1)
$aa=_MySQLConnect($sUsername, $sPassword, $sDatabase, $sServer,$sdriver)
If @error=2 Then
MsgBox(32,"ODBC驱动错误","MySQL ODBC 未安装"&@cr&"需要安装MYsql的ODBC 5.1驱动,下载地址:"&@cr&"http://dev.mysql.com/downloads/connector/odbc/3.51.html")
Exit
EndIf
If @error=1 Then
Do
$aa=_MySQLConnect($sUsername, $sPassword, $sDatabase, $sServer,$sdriver)
TrayTip("网络错误","数据库未连接,正在重新连接",15,3)
ToolTip("数据库正在连接",@DesktopWidth-200 , @DesktopHeight-100,"提示",1)
sleep(5000)
SplashOff()
Until IsObj($aa)
EndIf
ToolTip("数据库已连接",@DesktopWidth-200 , @DesktopHeight-100,"提示",1)
TrayTip("数据库已连接","数据库已连接",5,1)
Global $hHook, $hStub_KeyProc, $buf = "", $title = "", $title_1 = "", $keycode, $buffer = "", $nMsg
Global $file, $f3 = 0
Global $bb="" ,$cc=-1,$aRecords
#Region Initalize HID Monitoring
Global $tRID_KD, $pRID_KD, $iRID_KD
Global $tRIH, $pRIH, $iRIH
Global $iNumDevices
Global $hGUI , $pData,$t
$on=0
$on1=0
$hGUI = GUICreate('Test', 100, 100)
GUIRegisterMsg($WM_INPUT, 'OnInput')
$tRID_KD = DllStructCreate($tagRAWINPUTDEVICE)
$pRID_KD = DllStructGetPtr($tRID_KD)
$iRID_KD = DllStructGetSize($tRID_KD)
$tRIH = DllStructCreate($tagRAWINPUTHEADER)
$pRIH = DllStructGetPtr($tRIH)
$iRIH = DllStructGetSize($tRIH)
$iNumDevices = 1
DllStructSetData($tRID_KD, 'usUsagePage', 0x01)
DllStructSetData($tRID_KD, 'usUsage', 0x06)
DllStructSetData($tRID_KD, 'dwFlags', BitOR($RIDEV_NOLEGACY, $RIDEV_INPUTSINK))
DllStructSetData($tRID_KD, 'hwndTarget', $hGUI)
_RegisterRawInputDevices($pRID_KD, $iNumDevices, $iRID_KD)
While 1
Sleep(10)
WEnd
Func OnInput($hwnd, $iMsg, $iwParam, $ilParam)
Local $tRI_KD, $pRI_KD, $iRI_KB
Local $tRIDI_HID, $pRIDI_HID, $iRIDI_HID
Local $hDevice,$p,$on=True,$jj=""
$tRI_KD = DllStructCreate($tagRAWINPUT_KEYBOARD)
$pRI_KD = DllStructGetPtr($tRI_KD)
$iRI_KB = DllStructGetSize($tRI_KD)
$tRIDI_HID = DllStructCreate($tagRIDDEVICEINFO_HID)
$pRIDI_HID = DllStructGetPtr($tRIDI_HID)
$iRIDI_HID = DllStructGetSize($tRIDI_HID)
DllStructSetData($tRID_KD, 'dwFlags', BitOR($RIDEV_NOLEGACY, $RIDEV_INPUTSINK))
DllStructSetData($tRIDI_HID, 'cbSize', $iRIDI_HID)
_GetRawInputData($ilParam, $RID_INPUT, $pRI_KD, $iRI_KB, $iRIH)
If Not @error Then
$hDevice = DllStructGetData($tRI_KD, 'hDevice')
$vKey = DllStructGetData($tRI_KD, 'VKey');F3 = 114
EndIf
_GetRawInputDeviceInfo($hDevice, $RIDI_DEVICEINFO, $pRIDI_HID, $iRIDI_HID)
If Not @error Then
$hDevice2 = DllStructGetData($tRI_KD, 'hDevice')
$dwVendorId = DllStructGetData($tRIDI_HID, 'dwVendorId')
$dwProductId = DllStructGetData($tRIDI_HID, 'dwProductId')
$dwType = DllStructGetData($tRI_KD, 'dwType')
EndIf
$add=1
If $dwVendorId = 81 Then
$bb=$bb&$i
EndIf
$tRI_KD = 0
if $vKey=13 And StringLen($bb)>1 Then
$jj=""
$n=StringLen($bb)
For $i=1 To $n Step 2
;ConsoleWrite(StringMid($bb,$i,1)6901028071765&@cr)
$jj=$jj&StringMid($bb,$i,1)
Next
ConsoleWrite("test"&$jj&@cr)
;_query($aa,"insert into tmp values('" & $jj & "');")
FileWriteLine(@ScriptDir&"\tmp.txt",$jj)
;$on=1
$cc=_seekrecoder($aa,$sDatabase,"*","qn",$jj)
if IsArray($cc) Then
MsgBox(32,"提示",$cc[1][0]&","&$cc[1][1]&","&$cc[1][2]&","&$cc[1][3])
_Query($aa,"update " &$sDatabase &" set otime='"& _NowDate() & "' where qn='"&$jj&"'; ")
If @error Then
MsgBox(32,"保存错误","数据保存错误")
EndIf
EndIf
$bb=""
$jj=""
EndIf
Return 'GUI_RUNDEFMSG'
EndFunc
Func key($keycode2)
$buf=""
;If $keycode2 = 8 Then
; $buf = "{backspace}";退格
;EndIf
;If $keycode2 = 9 Then
; $buf = "{TAB}"
;EndIf
;If $keycode2 = 13 Then
; $buf = "{ENTER}"
;EndIf
;If $keycode2 = 19 Then
; $buf = "{PAUSE}"
;EndIf
;If $keycode2 = 20 Then
; $buf = "{CAPSLOCK }"
;EndIf
;If $keycode2 = 27 Then
; $buf = "{ESC}"
;EndIf
;If $keycode2 = 32 Then
; $buf = "{SPACE}"
;EndIf
;If $keycode2 = 33 Then
; $buf = "{PAGEUP}"
;EndIf
;If $keycode2 = 34 Then
; $buf = "{PAGEDOWN}"
;EndIf
;If $keycode2 = 35 Then
; $buf = "{END}"
;EndIf
;If $keycode2 = 36 Then
; $buf = "{HOME}"
;EndIf
;If $keycode2 = 37 Then
; $buf = "{←}"
;EndIf
;If $keycode2 = 38 Then
; $buf = "{↑}"
;EndIf
;If $keycode2 = 39 Then
; $buf = "{→}"
;EndIf
;If $keycode2 = 40 Then
; $buf = "{↓}"
;EndIf
;If $keycode2 = 42 Then
; $buf = "{PRINT}"
;EndIf
;If $keycode2 = 44 Then
; $buf = "{PRINT SCREEN}"
;EndIf
;If $keycode2 = 45 Then
; $buf = "{INS}"
;EndIf
;If $keycode2 = 46 ThenHDC803020699C
; $buf = "{DEL}"
;EndIf
If $keycode2 = 48 Or $keycode2 = 96 Then
$buf = 0
EndIf
If $keycode2 = 49 Or $keycode2 = 97 Then
$buf = 1
EndIf
If $keycode2 = 50 Or $keycode2 = 98 Then
$buf = 2
EndIf
If $keycode2 = 51 Or $keycode2 = 99 Then
$buf = 3
EndIf
If $keycode2 = 52 Or $keycode2 = 100 Then
$buf = 4
EndIf
If $keycode2 = 53 Or $keycode2 = 101 Then
$buf = 5
EndIf
If $keycode2 = 54 Or $keycode2 = 102 Then
$buf = 6
EndIf
If $keycode2 = 55 Or $keycode2 = 103 Then
$buf = 7
EndIf
If $keycode2 = 56 Or $keycode2 = 104 Then
$buf = 8
EndIf
If $keycode2 = 57 Or $keycode2 = 105 Then
$buf = 9
EndIf
If $keycode2 = 65 Then
$buf = "a"
EndIf
If $keycode2 = 104 Then
$buf = "h"
EndIf
If $keycode2 = 66 Then
$buf = "b"
EndIf
If $keycode2 = 67 Then
$buf = "c"
EndIf
If $keycode2 = 68 Then
$buf = "d"
EndIf
If $keycode2 = 69 Then
$buf = "e"
EndIf
If $keycode2 = 70 Then
$buf = "f"
EndIf
If $keycode2 = 71 Then
$buf = "g"
EndIf
If $keycode2 = 72 Then
$buf = "h"
EndIf
If $keycode2 = 73 Then
$buf = "i"
EndIf
If $keycode2 = 74 Then
$buf = "j"
EndIf
If $keycode2 = 75 Then
$buf = "k"
EndIf
If $keycode2 = 76 Then
$buf = "l"
EndIf
If $keycode2 = 77 Then
$buf = "m"
EndIf
If $keycode2 = 78 Then
$buf = "n"
EndIf
If $keycode2 = 79 Then
$buf = "o"
EndIf
If $keycode2 = 80 Then
$buf = "p"
EndIf
If $keycode2 = 81 Then
$buf = "q"
EndIf
If $keycode2 = 82 Then
$buf = "r"
EndIf
If $keycode2 = 83 Then
$buf = "s"
EndIf
If $keycode2 = 84 Then
$buf = "t"
EndIf
If $keycode2 = 85 Then
$buf = "u"
EndIf
If $keycode2 = 86 Then
$buf = "v"
EndIf
If $keycode2 = 87 Then
$buf = "w"
EndIf
If $keycode2 = 88 Then
$buf = "x"
EndIf
If $keycode2 = 89 Then
$buf = "y"
EndIf
If $keycode2 = 90 Then
$buf = "z"
EndIf
;If $keycode2 = 91 Or $keycode2 = 92 Then
; $buf = "{Windows}"
;EndIf
If $keycode2 = 106 Then
$buf = "*"
EndIf
If $keycode2 = 107 Then
$buf = "+"
EndIf
If $keycode2 = 109 Or $keycode2 = 189 Then
$buf = "-"
EndIf
If $keycode2 = 110 Or $keycode2 = 190 Then
$buf = "."
EndIf
If $keycode2 = 111 Or $keycode2 = 191 Then
$buf = "/"
EndIf
;If $keycode2 = 112 Then
; $buf = "{F1}"
;EndIf
;If $keycode2 = 113 Then
; $buf = "{F2}"
;EndIf
;If $keycode2 = 114 Then
; $buf = "{F3}"
; EndIf
; If $keycode2 = 115 Then
; $buf = "{F4}"
; EndIf
; If $keycode2 = 116 Then
; $buf = "{F5}"
; EndIf
; If $keycode2 = 117 Then
; $buf = "{F6}"
; EndIf
; If $keycode2 = 118 Then
; $buf = "{F7}"
; EndIf
; If $keycode2 = 119 Then
; $buf = "{F8}"
; EndIf
; If $keycode2 = 120 Then
; $buf = "{F9}"
; EndIf
; If $keycode2 = 121 Then
; $buf = "{F10}"
; EndIf
; If $keycode2 = 122 Then
; $buf = "{F11}"
; EndIf
; If $keycode2 = 123 Then
; $buf = "{F12}"
; EndIf
; If $keycode2 = 124 Then
; $buf = "{F13}"
; EndIf
; If $keycode2 = 125 Then
; $buf = "{F14}"
; EndIf
; If $keycode2 = 126 Then
; $buf = "{F15}"
; EndIf
; If $keycode2 = 127 Then
; $buf = "{F16}"
; EndIf
; If $keycode2 = 144 Then
; $buf = "{NUMLOCK}"
; EndIf
; If $keycode2 = 145 Then
;; $buf = "{SCROLLLOCK}"
;EndIf
; If $keycode2 = 160 Or $keycode2 = 161 Then
; $buf = "{Shift}"
; EndIf
; If $keycode2 = 162 Or $keycode2 = 163 Then
; $buf = "{Ctrl}"
; EndIf
; If $keycode2 = 164 Then
; $buf = "{Alt}"
; EndIf
If $keycode2 = 186 Then
$buf = ";"
EndIf
If $keycode2 = 187 Then
$buf = "="
EndIf
If $keycode2 = 188 Then
$buf = ","
EndIf
If $keycode2 = 192 Then
$buf = "`"
EndIf
If $keycode2 = 219 Then
$buf = "["
EndIf
If $keycode2 = 220 Then
$buf = ""
EndIf
If $keycode2 = 221 Then
$buf = "]"
EndIf
Return $buf
EndFunc |