如何用ruby触发windows快捷方式

时间:2013-02-13 22:43:28

标签: ruby windows

我想触发Windows快捷方式ctrl+d(在Windows环境中)。我为了简单起见使用FFI宝石。这是我尝试过的,但它无法正常工作

require 'ffi'

 module Win

   extend FFI::Library
   ffi_lib 'User32'
   ffi_convention :stdcall

   attach_function :keybd_event, [ :uchar, :uchar, :int, :pointer ], :void

 end

KEYEVENTF_KEYUP = 2
SW_HIDE         = 0
SW_SHOW         = 5
SW_SHOWNORMAL   = 1
VK_CONTROL      = 0x11
VK_F4           = 0x73
VK_MENU         = 0x12
VK_RETURN       = 0x0D
VK_SHIFT        = 0x10
VK_SNAPSHOT     = 0x2C
VK_TAB      = 0x09
GMEM_MOVEABLE = 0x0002
CF_TEXT = 1
 D = 0x44

Win.keybd_event(VK_CONTROL,0,0, nil);
Win.keybd_event(D,0,0 , nil); 
Win.keybd_event(D,0, KEYEVENTF_KEYUP    ,nil)
Win.keybd_event(VK_CONTROL,0,KEYEVENTF_KEYUP,nil);

0 个答案:

没有答案