请问以上代码为何无法判断insert键的状态?(100分)

  • 主题发起人 主题发起人 wuyund
  • 开始时间 开始时间
W

wuyund

Unregistered / Unconfirmed
GUEST, unregistred user!
if (GetKeyState(VK_INSERT))=0 &nbsp;then<br>&nbsp; &nbsp;statusbar1.Panels[4].Text:='插入'<br>else<br>&nbsp; &nbsp;statusbar1.Panels[4].Text:='覆写';<br>请问以上代码为何无法判断insert键的状态,应该如何改写?
 
以上代码在XP和D7上可以判断insert键的状态。<br>
 
大哥,我用的是win98+D7却无法判断!!那该怎么办?
 
你把上面的代码加在哪,比如说可以把它加到TIMER组件中,声明(getkeystate可以用在win98上)
 
我把它放在creatform事件中,难道不对吗?
 
放在Timer组件的ontime事件中也不行!!
 
是吗?我以前用可没有这种现象的呀!
 
以下全部给你了:<br><br>function GetKeyLock(vcode: Integer):boolean; &nbsp;//获取或设置键盘状态<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //VK_INSERT VK_CAIPTAL VK_NUMLOCK<br>begin<br>result:=Odd(GetKeyState(vcode));<br>end;<br><br>function SetKeyLock(vcode: Integer; down: Boolean):boolean;<br>begin<br>// &nbsp;if Odd(GetAsyncKeyState(vcode)) &lt;&gt; down then<br>&nbsp; result:=Odd(GetKeyState(vcode));<br>&nbsp; if Odd(GetKeyState(vcode)) &lt;&gt; down then<br>&nbsp; begin<br>&nbsp; &nbsp; keybd_event(vcode, MapVirtualkey(vcode, 0),<br>&nbsp; &nbsp; &nbsp; KEYEVENTF_EXTENDEDKEY, 0);<br>&nbsp; &nbsp; keybd_event(vcode, MapVirtualkey(vcode, 0),<br>&nbsp; &nbsp; &nbsp; KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0);<br>&nbsp; end;<br><br>end;
 
就这样就行了:<br>先将Form1的KeyPreview属性设为True;<br>procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;<br>&nbsp; Shift: TShiftState);<br>begin<br>&nbsp; case Key of<br>&nbsp; &nbsp; VK_INSERT:<br>&nbsp; &nbsp; &nbsp; if statusbar1.Panels[4].Text = '覆写' then<br>&nbsp; &nbsp; &nbsp; &nbsp; statusbar1.Panels[4].Text:='插入'<br>&nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; statusbar1.Panels[4].Text:='覆写';<br>&nbsp; end;<br>end;<br>
 
我在win2000 server, delphi 5中测试通过!! 另外当然不能放在createform中,这样它只在Form建立时执行一次!<br>
 
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;<br>&nbsp; Shift: TShiftState);<br>var<br>&nbsp; KeyState: TKeyboardState;<br>begin<br>&nbsp; GetKeyboardState(KeyState);<br>&nbsp; if KeyState[VK_Insert]=1 then<br>&nbsp; &nbsp; Caption:='Insert'<br>&nbsp; else<br>&nbsp; &nbsp; Caption:='Overwrite'<br>end;
 
谢谢各位!!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
回复
0
查看
575
不得闲
后退
顶部