很简单:<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> private<br> { Private declarations }<br> procedure WMKeyDown(var Message: TWMKEY); message WM_KEYDOWN;<br> procedure WMKeyUp(var Message: TWMKEY); message WM_KEYUP;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.WMKeyDown(var Message: TWMKey);<br>begin<br> inherited;<br><br> //判断按下<br> if ((message.KeyData) and ($2a shl 16))=($2a shl 16) then<br> showmessage('Left shift pressed')<br> else if ((message.KeyData) and ($36 shl 16))=($36 shl 16) then<br> showmessage('Right shift pressed');<br><br>end;<br><br>procedure TForm1.WMKeyUp(var Message: TWMKEY);<br>begin<br> inherited;<br> //判断抬起<br> if ((message.KeyData) and ($2a shl 16)=($2a shl 16)) then<br> showmessage('Left shift up')<br> else if ((message.KeyData) and ($36 shl 16))=($36 shl 16) then<br> showmessage('Right shift Up');<br>end;<br><br>end.<br><br>根据这些在程序里设置标志,记录左右shift键的状态,需要的时候判断即可。