请问如何用VFP代码实现模拟ctrl+Win的按键动作?
请问如何用VFP代码实现模拟ctrl+Win的按键动作?
MESSAGEBOX( INKEY(0))返回一个按键的值
ctrl+Win好像不是一个有值的按键,就象单独按ctrl或shift一样
of = CREATEOBJECT("form1") of.show(1) DEFINE CLASS form1 as Form ADD OBJECT edit1 as editbox WITH left=10,top=10,width=300,height=200 PROCEDURE init BINDEVENT(this.hWnd, 0x100, this, "myKeyDown") BINDEVENT(this.hWnd, 0x101, this, "myKeyUp") BINDEVENT(this.hWnd, 0x104, this, "mySysKeyDown") BINDEVENT(this.hWnd, 0x105, this, "mySysKeyUp") ENDPROC PROCEDURE myKeyDown(hWnd, Msg, wParam, lParam) this.edit1.SelText = "KeyDown " + TRANSFORM(wParam,"@0") + ", " + TRANSFORM(lParam,"@0") + 0h0D0A ENDPROC PROCEDURE myKeyUp(hWnd, Msg, wParam, lParam) this.edit1.SelText = "KeyUp " + TRANSFORM(wParam,"@0") + ", " + TRANSFORM(lParam,"@0") + 0h0D0A ENDPROC PROCEDURE mySysKeyDown(hWnd, Msg, wParam, lParam) this.edit1.SelText = "SysKeyDown " + TRANSFORM(wParam,"@0") + ", " + TRANSFORM(lParam,"@0") + 0h0D0A ENDPROC PROCEDURE mySysKeyUp(hWnd, Msg, wParam, lParam) this.edit1.SelText = "SysKeyUp " + TRANSFORM(wParam,"@0") + ", " + TRANSFORM(lParam,"@0") + 0h0D0A ENDPROC ENDDEFINE
DECLARE Long keybd_event IN user32 long,long,long,long #define KEYEVENTF_KEYUP 2 #define VK_CONTROL 0x11 #define VK_LWIN 0x5B #define VK_E 0x45 of = CREATEOBJECT("form1") of.show(1) DEFINE CLASS form1 as Form ADD OBJECT cmd1 as commandbutton with left=10,top=10,width=100,height=22,caption="Ctrl+Win" ADD OBJECT cmd2 as commandbutton with left=120,top=10,width=100,height=22,caption="Win+E" ADD OBJECT edit1 as editbox WITH left=10,top=40,width=300,height=200 PROCEDURE init BINDEVENT(this.hWnd, 0x100, this, "myKeyDown") BINDEVENT(this.hWnd, 0x101, this, "myKeyUp") BINDEVENT(this.hWnd, 0x104, this, "mySysKeyDown") BINDEVENT(this.hWnd, 0x105, this, "mySysKeyUp") ENDPROC PROCEDURE myKeyDown(hWnd, Msg, wParam, lParam) this.edit1.SelText = "KeyDown " + TRANSFORM(wParam,"@0") + ", " + TRANSFORM(lParam,"@0") + 0h0D0A ENDPROC PROCEDURE myKeyUp(hWnd, Msg, wParam, lParam) this.edit1.SelText = "KeyUp " + TRANSFORM(wParam,"@0") + ", " + TRANSFORM(lParam,"@0") + 0h0D0A ENDPROC PROCEDURE mySysKeyDown(hWnd, Msg, wParam, lParam) this.edit1.SelText = "SysKeyDown " + TRANSFORM(wParam,"@0") + ", " + TRANSFORM(lParam,"@0") + 0h0D0A ENDPROC PROCEDURE mySysKeyUp(hWnd, Msg, wParam, lParam) this.edit1.SelText = "SysKeyUp " + TRANSFORM(wParam,"@0") + ", " + TRANSFORM(lParam,"@0") + 0h0D0A ENDPROC PROCEDURE cmd1.click Keybd2(VK_CONTROL, VK_LWIN) && Ctrl+Win ENDPROC PROCEDURE cmd2.click Keybd2(VK_LWIN, VK_E) && Win+E 打开资源管理器 ENDPROC ENDDEFINE FUNCTION Keybd2(vk1, vk2) keybd_event(vk1, 0, 0, 0) keybd_event(vk2, 0, 0, 0) keybd_event(vk2, 0, KEYEVENTF_KEYUP, 0) keybd_event(vk1, 0, KEYEVENTF_KEYUP, 0) ENDFUNC
[此贴子已经被作者于2022-1-4 05:47编辑过]