iPod touch を PowerPoint のリモコンにしてみる
前回のエントリで欲しい欲しいと言っていた iPod touch を買ってしまったのでいろいろ遊んでみている.
プレゼンをやっているときに,スライドの戻る/進むを iPod touch で操作できたら
きっと楽しいだろうなーと思ったのでそんなスクリプトを書いてみた.
remotePowerPoint.rb
#!ruby # Remote Controller of PowerPoint for iPhone/iPod touch # # license: Public Domain # OS : Windows # update: 2007/11/18 # author: mallowlabs # blog: http://d.hatena.ne.jp/mallowlabs/ # # How To Use: # 1. ruby remotePowerPoint.rb # 2. access to "http://HOSTNAME:4321/index" by iPhone/iPod touch # 3. enjoy! # require "dl/import" module User32 VK_F5 = 0x0074 VK_DOWN = 0x28 VK_UP = 0x26 VK_ESCAPE = 0x1B LIB = DL.dlopen("user32") def keybd_event(keycode) keybdEvent = LIB["keybd_event", "0HHLl"] r, rs = keybdEvent.call(keycode, 0, 0, 0) end module_function :keybd_event end require "webrick" require "net/http" #$stdout.sync = true @config = { "server" => { } } server_config = { :Port => 4321, # :Logger => WEBrick::Log.new(nil, 0), # :AccessLog => WEBrick::Log.new(nil, 0), }.update(@config["server"]) srv = WEBrick::HTTPServer.new(server_config) srv.mount_proc("/index") do |req, res| res.content_type = "text/html" res.body = <<END <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/> <style type="text/css"> <!-- .box { width: 48%; text-align: center; border: 1px solid blue; } .box a { font-size: 20px; } --> </style> <script type="text/javascript"> <!-- var action = function(url) { var xhr = new XMLHttpRequest(); xhr.open("GET", url, true); xhr.send(""); } --> </script> <title>Remote PowerPoint</title> </head> <body> <h1><a href="/lite/">Remote PowerPoint</a></h1> <table style="width:100%;text-align:center;"> <tr> <td class="box"> <a href="javascript:action('/start');">F5</a> </td> <td class="box"> <a href="javascript:action('/esc');">Esc</a> </td> </tr> <tr> <td class="box"> <a href="javascript:action('/prev');">←</a> </td> <td class="box"> <a href="javascript:action('/next');">→</a> </td> </tr> </table> </body> </html> END end srv.mount_proc("/start") do |req, res| User32.keybd_event(User32::VK_F5) res.content_type = "text/plain" res.body = "start" end srv.mount_proc("/esc") do |req, res| User32.keybd_event(User32::VK_ESCAPE) res.content_type = "text/plain" res.body = "esc" end srv.mount_proc("/prev") do |req, res| User32.keybd_event(User32::VK_UP) res.content_type = "text/plain" res.body = "prev" end srv.mount_proc("/next") do |req, res| User32.keybd_event(User32::VK_DOWN) res.content_type = "text/plain" res.body = "next" end trap (:INT) { srv.shutdown } srv.start
上のスクリプトを
$ruby remotePowerPoint.rb
で実行すると WEBrick サーバが立つので
PowerPoint をアクティブにして iPod touch の Safari でアクセスする.
すると以下のような画面が表示されるので,リンクをクリックするとスライドが変わる.
でも,なぜかリンクをクリックしてからスライドが切り替わるまでに8秒くらいかかってしまった.
原因はちょっとわからない.HTTP でやるのは無理があるのかなー.
# 「うちの環境ではサクサク動いたぜ!」みたいな動作報告待ってます.
# もしくは原因をご存知の方はコメントください.
動作原理
- WEBrick でサーバを立てて iPod touch の Safari からのアクセスを待つ.
- アクセスがあったら index ページ(上の画像) を表示
- ボタンがクリックされると XMLHttpRequest で next 等のページを GET
- next 等のページが叩かれると Windows API の keybd_event() を叩いてキーボード(VK_DOWN等)をエミュレート
- PowerPoint のスライドが変わる
- やったー!
まとめ
リンクをクリックしてからスライドが切り替わるまでに
かなり時間がかかるのではっきり言って使い物にならない.
8秒くらい適当にしゃべって間をつなぐというのも考えたが,
タイムラグはランダムなので結構難しい.
誰かが問題を解決してくれるのを待ちたい(他力本願).