怎么模拟右Ctrl键?(100分)

  • 主题发起人 主题发起人 Buder
  • 开始时间 开始时间
B

Buder

Unregistered / Unconfirmed
GUEST, unregistred user!
“修改HKEY_LOCAL_MACHINE/System/CurrentControlSet/Services/i8042prt/Parameters÷CrashOnCtrlScroll”的键值改为 1(0 是关闭此项功能)。重启后按住键盘右面的 Ctrl,然后再按下 Scroll lock 键两次,这样蓝屏就出现了。”<br><br>我想模拟上面的按键过程,但我没办法模拟右Ctrl键!<br>用<br>&nbsp;keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0),0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;keybd_event(VK_SCROLL, MapVirtualKey(VK_SCROLL, 0), 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;keybd_event(VK_SCROLL, MapVirtualKey(VK_SCROLL, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;keybd_event(VK_SCROLL, MapVirtualKey(VK_SCROLL, 0), 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;keybd_event(VK_SCROLL, MapVirtualKey(VK_SCROLL, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0),KEYEVENTF_KEYUP,0);<br>没有,应该是VK_CTRL不区分左右的问题!<br><br>我该怎么模拟右CTRL键呢?
 
下面是一个模拟按键的单元,你可以分析一下!<br>主要部分是Keybd_Event函数的使用!<br>{****************************************************}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendKeys Unit for Delphi 32 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp; &nbsp;Copyright (c) 1999 by Borut Batagelj (Slovenia) }<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Aleksey Kuznetsov (Ukraine) &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Home Page: www.utilmind.com &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;E-Mail: info@utilmind.com &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{****************************************************}<br><br>unit SendKeys;<br><br>interface<br><br>uses<br>&nbsp; Windows, SysUtils;<br><br>const<br>&nbsp; SK_BKSP = #8;<br>&nbsp; SK_TAB = #9;<br>&nbsp; SK_ENTER = #13;<br>&nbsp; SK_ESC = #27;<br>&nbsp; SK_ADD = #107;<br>&nbsp; SK_SUB = #109;<br>&nbsp; SK_F1 = #228;<br>&nbsp; SK_F2 = #229;<br>&nbsp; SK_F3 = #230;<br>&nbsp; SK_F4 = #231;<br>&nbsp; SK_F5 = #232;<br>&nbsp; SK_F6 = #233;<br>&nbsp; SK_F7 = #234;<br>&nbsp; SK_F8 = #235;<br>&nbsp; SK_F9 = #236;<br>&nbsp; SK_F10 = #237;<br>&nbsp; SK_F11 = #238;<br>&nbsp; SK_F12 = #239;<br>&nbsp; SK_HOME = #240;<br>&nbsp; SK_END = #241;<br>&nbsp; SK_UP = #242;<br>&nbsp; SK_DOWN = #243;<br>&nbsp; SK_LEFT = #244;<br>&nbsp; SK_RIGHT = #245;<br>&nbsp; SK_PGUP = #246;<br>&nbsp; SK_PGDN = #247;<br>&nbsp; SK_INS = #248;<br>&nbsp; SK_DEL = #249;<br>&nbsp; SK_SHIFT_DN = #250;<br>&nbsp; SK_SHIFT_UP = #251;<br>&nbsp; SK_CTRL_DN = #252;<br>&nbsp; SK_CTRL_UP = #253;<br>&nbsp; SK_ALT_DN = #254;<br>&nbsp; SK_ALT_UP = #255;<br><br>procedure SendKeyString(Text: String);<br><br>implementation<br><br>procedure SendKeyString(Text: String);<br>var<br>&nbsp; &nbsp;i: Integer;<br>&nbsp; &nbsp;Shift: Boolean;<br>&nbsp; &nbsp;vk, ScanCode: Word;<br>&nbsp; &nbsp;ch: Char;<br>&nbsp; &nbsp;c, s: Byte;<br>const<br>&nbsp; &nbsp;vk_keys: Array[0..9] of Byte =<br>&nbsp; &nbsp; &nbsp; (VK_HOME, VK_END, VK_UP, VK_DOWN, VK_LEFT,<br>&nbsp; &nbsp; &nbsp; &nbsp;VK_RIGHT, VK_PRIOR, VK_NEXT, VK_INSERT, VK_DELETE);<br>&nbsp; &nbsp;vk_shft: Array[0..2] of Byte = (VK_SHIFT, VK_CONTROL, VK_MENU);<br>&nbsp; &nbsp;flags: Array[False..True] of Integer = (KEYEVENTF_KEYUP, 0);<br>begin<br>&nbsp; &nbsp;Shift := False;<br>&nbsp; &nbsp;for i := 1 to Length(Text) do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;ch := Text;<br>&nbsp; &nbsp; &nbsp;if ch &gt;= #250 then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;s := Ord(ch) - 250;<br>&nbsp; &nbsp; &nbsp; &nbsp;Shift := not Odd(s);<br>&nbsp; &nbsp; &nbsp; &nbsp;c := vk_shft[s shr 1];<br>&nbsp; &nbsp; &nbsp; &nbsp;ScanCode := MapVirtualKey(c,0);<br>&nbsp; &nbsp; &nbsp; &nbsp;Keybd_Event(c, Scancode, Flags[shift], 0);<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp;vk := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp;if ch &gt;= #240 then<br>&nbsp; &nbsp; &nbsp; &nbsp; c := vk_keys[Ord(ch) - 240]<br>&nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; if ch &gt;= #228 then {228 (F1) =&gt; $70 (vk_F1)}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;c := Ord(ch) - 116<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ch &lt; #110 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c := Ord(ch)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;vk := VkKeyScan(ch);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;c := LoByte(vk);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp;ScanCode := MapVirtualKey(c,0);<br>&nbsp; &nbsp; &nbsp; &nbsp;if not Shift and (Hi(vk) &gt; 0) then { $2A = scancode of VK_SHIFT }<br>&nbsp; &nbsp; &nbsp; &nbsp; Keybd_Event(VK_SHIFT, $2A, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;Keybd_Event(c,scancode, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;Keybd_Event(c,scancode, KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp;if not Shift and (Hi(vk) &gt; 0) then<br>&nbsp; &nbsp; &nbsp; &nbsp; Keybd_Event(VK_SHIFT, $2A, KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>end;<br>end. <br>
 
老兄,CTRL是可以分左右的<br>左:VK_LCONTROL<br>右:VK_RCONTROL
 
procedure PressKey(VKey: Byte);<br>begin<br>&nbsp; Keybd_event(VKey, 0, 0, 0);<br>&nbsp; Keybd_event(VKey, 0, KEYEVENTF_KEYUP, 0);<br>end;<br><br>然后再调用<br>PressKey(VK_LCONTROL);//模拟左CTRL<br>PressKey(VK_RCONTROL);//模拟右CTRL
 
不行的,看windows.pas<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>
 
后退
顶部