Ruby调用WindowsAPI模拟按键

2015-09-06 0 536
Ruby调用WindowsAPI模拟按键
require 'win32api'

class KeyBoardHelper
    attr_reader :ctrl, :shift, :alt, :win

    def initialize
        @ctrl, @shift, @alt, @win = 0x11, 0x10, 0x12, 0x5b
        @bScan, @downFlag, @upFlag, @extraInfo = 0x45, 1, 3, 0

        @ke = Win32API.new('User32.dll', 'keybd_event', 'IIII')
    end

    def press(key, &block)
        key = key.upcase.bytes[0] if key.instance_of? String

        @ke.call(key, @bScan, @downFlag, @extraInfo)
        yield if block
        @ke.call(key, @bScan, @upFlag, @extraInfo)
    end

    def test_paste
        press(@ctrl) {
            press('v')
        }
    end
end

=begin
h = KeyBoardHelper.new
sleep 3
h.test_paste
=end

遇见资源网 ruby Ruby调用WindowsAPI模拟按键 http://www.ox520.com/16441.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务