在 win95 中如何检测(区分)左右 shift 键(200分)

  • 主题发起人 主题发起人 cola
  • 开始时间 开始时间
C

cola

Unregistered / Unconfirmed
GUEST, unregistred user!
不是在 NT 下面 GETKEYSTATE 的 VK_LSHIFT 和 VK_RSHIFT 没有用<br><br>这个问题我急需答案,如果200分不够,我可以再加
 
好象老问题中已经有解决方法了,<br>&nbsp;我再把Delphi源码及MSDN中相关的内容贴一下吧。<br>{ VK_L &amp; VK_R - left and right Alt, Ctrl and Shift virtual keys.<br>&nbsp; Used only as parameters to GetAsyncKeyState() and GetKeyState().<br>&nbsp; No other API or message will distinguish left and right keys in this way. }<br>&nbsp; {$EXTERNALSYM VK_LSHIFT}<br>&nbsp; VK_LSHIFT = 160;<br>&nbsp; {$EXTERNALSYM VK_RSHIFT}<br>&nbsp; VK_RSHIFT = 161;<br>&nbsp; {$EXTERNALSYM VK_LCONTROL}<br>&nbsp; VK_LCONTROL = 162;<br>&nbsp; {$EXTERNALSYM VK_RCONTROL}<br>&nbsp; VK_RCONTROL = 163;<br>&nbsp; {$EXTERNALSYM VK_LMENU}<br>&nbsp; VK_LMENU = 164;<br>&nbsp; {$EXTERNALSYM VK_RMENU}<br>&nbsp; VK_RMENU = 165;<br><br>An application calls GetKeyState in response to a keyboard-input message. <br>This function retrieves the state of the key when the input message<br>&nbsp;was generated. <br><br>To retrieve state information for all the virtual keys, use the GetKeyboardState function. <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
 
VK_LSHIFT,VK_RSHIFT 这些参数好象只能在 NT 下用,WIN95/98 下是不能用的<br>看看还有没有其他办法。。。<br>最好给出源代码
 
看来只有在WM_KEYDOWN中判断键盘扫描码了
 
9X下似乎只能如此了;(
 
keyPress<br>if Key = 160 then<br>begin<br>end<br>else if key = 161 &nbsp;<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;end;
 
在鼠标事件中有参数可以确定的具体的不太清楚DELPHI 5.0 应该可以分的开的,如是键盘<br>事件判断扫描吗好了并不复杂
 
能给出源代码么?
 
很简单:<br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; procedure WMKeyDown(var Message: TWMKEY); message WM_KEYDOWN;<br>&nbsp; &nbsp; procedure WMKeyUp(var Message: TWMKEY); message WM_KEYUP;<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.WMKeyDown(var Message: TWMKey);<br>begin<br>&nbsp; &nbsp; &nbsp;inherited;<br><br>&nbsp; &nbsp; &nbsp;//判断按下<br>&nbsp; &nbsp; &nbsp;if ((message.KeyData) and ($2a shl 16))=($2a shl 16) then<br>&nbsp; &nbsp; &nbsp; &nbsp; showmessage('Left shift pressed')<br>&nbsp; &nbsp; &nbsp;else if ((message.KeyData) and ($36 shl 16))=($36 shl 16) then<br>&nbsp; &nbsp; &nbsp; &nbsp; showmessage('Right shift pressed');<br><br>end;<br><br>procedure TForm1.WMKeyUp(var Message: TWMKEY);<br>begin<br>&nbsp; &nbsp; &nbsp;inherited;<br>&nbsp; &nbsp; &nbsp;//判断抬起<br>&nbsp; &nbsp; &nbsp;if ((message.KeyData) and ($2a shl 16)=($2a shl 16)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showmessage('Left shift up')<br>&nbsp; &nbsp; &nbsp;else if ((message.KeyData) and ($36 shl 16))=($36 shl 16) then<br>&nbsp; &nbsp; &nbsp; &nbsp; showmessage('Right shift Up');<br>end;<br><br>end.<br><br>根据这些在程序里设置标志,记录左右shift键的状态,需要的时候判断即可。
 
我的这段代码应该可以吧?
 
又学了一招,谢谢!
 
cola:如果你还要继续讨论请定期提前你的帖子,如果不想继续讨论请结束帖子。<br>
 
接受答案了.
 
后退
顶部