Ruby 获取键盘输入

###################################################
#Main Application Code Start
###################################################

puts "---begin---"

#display msgbox to ask user to input from keyboard
MessageBox = Win32::API.new("MessageBox", 'LPPI', 'I', "user32")
MessageBox.call(0, "Please input 1 to switch to PRT1 or 2 to switch to PRT2", "MsgBox", 0)

#get input from keyboard
char = getchar
if char==49   #if input is 1, 49 is ASC for 1
  prt = "PRT1"
  puts "---Will switch to PRT1!---"
elsif char==50    #if input is 2, 50 is ASC for 2
  prt = "PRT2"
  puts "---Will switch to PRT2!---"
else    #error handling if input is not 1 or 2
  raise RuntimeError, "bad argument"
end

#get input for pool name from keyboard
box_name = gets.chomp
puts box_name
box_name = "fp"+box_name
puts box_name
#MessageBox.call(4,"You want to operate "+box_name,"Is it OK?",3)
puts box_name+" pool is selected!"

#start to open ie to config page
$ie = Watir::IE.new_process
$ie.set_fast_speed
$ie.goto(CONFIG_URL)

#refresh page and try to find right config link
$ie.select_list(:name, "box").select(box_name)
$autoit = WIN32OLE.new('AutoItX3.Control')
puts "---refresh---"
sleep 2
$autoit.Send('{F5}')#refresh the page
if char == 49  #config to PRT1
  i = 4
else    #config to PRT2
  i = 5
end

while i>0 do
     $autoit.Send('{TAB}')
     sleep 1 
     i=i-1
end
$autoit.Send('{ENTER}')  
puts "Setting is proceeding..."
sleep 10

shell = WIN32OLE.new('Shell.Application')
windows = shell.Windows
i = 0
windows.each {|w| puts i.to_s + " " + w.LocationURL; i+=1 }
if i ==2
  #puts "---Successfully Set "+POOL_NAME+" to PRT1---"
  MessageBox.call(0, box_name+" switch to "+prt+" successfully!", "MsgBox", 0)
else
  MessageBox.call(0, box_name+" Switch to "+prt+" Failed!", "MsgBox", 0)
end
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值