Skip to content

Instantly share code, notes, and snippets.

@jon-uw
Created November 5, 2013 09:04
Show Gist options
  • Save jon-uw/7315965 to your computer and use it in GitHub Desktop.
Save jon-uw/7315965 to your computer and use it in GitHub Desktop.
stimulate windows key stroking from oschina.net
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
def press_ctrl
press(@ctrl)
end
end
=begin
h = KeyBoardHelper.new
sleep 3
h.test_paste
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment