时间: 2021-07-31 作者:daque
陈耀华 在少许运用软硬件中,搜集键盘和鼠目标消息比拟要害,而vb5.0又没有供给相映的因变量到达这个手段。本质上不妨用相映的api来实行,如笔者的键盘消息为:键盘典型:ibm 101/102巩固键盘,反复击键速率每秒钟15个字符,键盘延时0秒,光标闪耀间隙500ms;鼠标为ms双键,双击间隙为300ms。运转以次步调就不妨搜集到之上消息。 步调代码: 创造一模块,定名为info.bas,api证明如次: option explicit ′收集键盘消息的api declare function getcaretblinktime lib ″user32″ () as long public const spi—getkeyboardspeed = 10 public const spi—getkeyboarddelay = 22 declare function systemparametersinfo lib ″user32″ alias ″systemparametersinfoa″ (byval uaction as long, byval uparam as long, lpvparam as any, byval fuwinini as long) as long declare function getkeyboardtype lib ″user32″ (byval ntypeflag as long) as long ′收集鼠标消息的api declare function getdoubleclicktime lib ″user32″ () as long public const sm—cmousebuttons = 43 declare function getsystemmetrics lib ″user32″ (byval nindex as long) as long public const sm—mousepresent = 19 主窗口(form1)上放command1,timer1及4个label,辨别定名为lblkeyboard,lblrepeatspeed,lblrepeatdelay,lblcaretflash.表露键盘的消息建一shape1,表白光标闪耀的功效。2个label,辨别命为lblmouse,lbldblclick表露鼠目标消息。 private sub command1—click() dim r as long dim t as string dim k as long dim q as long k = getkeyboardtype(0) if k = 1 then t = ″pc or compatible 83-key keyboard″ if k = 2 then t = ″olivetti 102-key keyboard″ if k = 3 then t = ″at or compatible 84-key keyboard″ if k = 4 then t = ″enhanced(ibm) 101-102-key keyboard″ if k = 5 then t = ″nokia 1050 keyboard″ if k = 6 then t = ″nokia 9140 keyboard″ if k = 7 then t = ″japanese keyboard″ lblkeyboard = ′type of keyboard : ″ & t q = systemparametersinfo(spi—getkeyboarddelay, 0, r, 0) lblrepeatdelay = ″keyboard repeat delay = ″ & r & ″ seconds″ q = systemparametersinfo(spi—getkeyboardspeed, 0, r, 0) scrrepeatspeed = r lblrepeatspeed = ″keyboard repeat speed = ″ & r & ″ characters per second.″ timer1.interval = getcaretblinktime scrcaretflash = getcaretblinktime lblcaretflash = ″caret flash speed = ″ & getcaretblinktime & ″ms″ if getsystemmetrics(sm_mousepresent) = 1 then lblmouse = ″standard mouse present with ″ & getsystemmetrics(sm—cmousebuttons) & ″ buttons.″ else lblmouse = ″no mouse present.″ exit sub end if lbldblclick = ″double click speed = ″ & getdoubleclicktime & ″ms″ end sub private sub form—load() call command1—click end sub private sub timer1—timer() shape1.visible = not shape1.visible end sub 按f5运转,点击command1即可搜集到键盘和鼠标消息。 此步调在pwin95和华文vb5.0中胜利运转经过,已应用到本质处事中。