AppleRemoteをRubyで使う
      Tim Burks氏の
Use your Apple Remote from Rubyというサイトに
AppleRemote(最近のMacに付属してくる赤外線リモコン)をRubyで使う方法が載っている。
Martin Kahr氏が作った
AppleRemote用ライブラリを
framework化してビルドしてRubyから呼べばよいらしい。
    現在(2008/1)のKahr氏のシステムは、 ソースコードの構成やライブラリの引数がBurks氏の記事とは異なっているが、 必要そうなものを全部まとめてframework化して以下のようにコードを少し変えると 無事動かすことができた。
require 'osx/cocoa'
include OSX
NSBundle.bundleWithPath("/Library/Frameworks/AppleRemote.framework").load
ns_import :AppleRemote
class AppleRemoteDelegate < NSObject
  addRubyMethod_withType('sendRemoteButtonEvent:pressedDown:remoteControl:', 'v@:ii@')
  def sendRemoteButtonEvent_pressedDown_remoteControl(buttonIdentifier, pressDown, remoteControl)
    puts "button #{buttonIdentifier}, pressed #{pressDown}"
  end
end
appleRemoteDelegate = AppleRemoteDelegate.alloc.init
appleRemote = AppleRemote.alloc.initWithDelegate(appleRemoteDelegate)
appleRemote.startListening self
NSApplication.sharedApplication.run
    


0 Comments:
Post a Comment
Links to this post:
Create a Link
<< Home