Sha256: fc3e2988a1925f07b6ffefee6a2a10248c673434faef57b22870d489a12d5bee

Contents?: true

Size: 1.03 KB

Versions: 22

Compression:

Stored size: 1.03 KB

Contents

require 'rubygems' # ugh
require 'ffi'

module Muter
  # from msdn on keybd_event ...
  
  VK_VOLUME_DOWN = 0xAE
  VK_VOLUME_UP = 0xAF
  VK_VOLUME_MUTE = 0xAD
  KEYEVENTF_KEYUP = 2
  
  extend FFI::Library
  ffi_lib 'user32'
  ffi_convention :stdcall

  attach_function :keybd_event, [ :uchar, :uchar, :int, :pointer ], :void
  
  def hit_mute_key
    # simulate pressing the mute key
    keybd_event(VK_VOLUME_MUTE, 0, 0, nil)
    keybd_event(VK_VOLUME_MUTE, 0, KEYEVENTF_KEYUP, nil)
  end
  
  def hit_volume_up_key
    keybd_event(VK_VOLUME_UP, 0, 0, nil)
    keybd_event(VK_VOLUME_UP, 0, KEYEVENTF_KEYUP, nil)
  end
  
  def hit_volume_down_key
    keybd_event(VK_VOLUME_DOWN, 0, 0, nil)
    keybd_event(VK_VOLUME_DOWN, 0, KEYEVENTF_KEYUP, nil)
  end
  
  def mute!
    #unmute! # just in case
    hit_mute_key
  end

  # TODO better for doze 7...
  def unmute!
    hit_mute_key # Windows XP...
    hit_volume_down_key
    hit_volume_up_key
  end
      
  # allow for Muter.xxx
  extend self
  
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sensible-cinema-0.17.0 lib/muter.rb
sensible-cinema-0.16.7 lib/muter.rb
sensible-cinema-0.16.5 lib/muter.rb
sensible-cinema-0.16.3 lib/muter.rb
sensible-cinema-0.16.2 lib/muter.rb
sensible-cinema-0.16.1 lib/muter.rb
sensible-cinema-0.15.0 lib/muter.rb
sensible-cinema-0.14.6 lib/muter.rb
sensible-cinema-0.14.5 lib/muter.rb
sensible-cinema-0.14.4 lib/muter.rb
sensible-cinema-0.14.3 lib/muter.rb
sensible-cinema-0.14.1 lib/muter.rb
sensible-cinema-0.13.1 lib/muter.rb
sensible-cinema-0.13.0 lib/muter.rb
sensible-cinema-0.12.0 lib/muter.rb
sensible-cinema-0.11.0 lib/muter.rb
sensible-cinema-0.10.2 lib/muter.rb
sensible-cinema-0.10.1 lib/muter.rb
sensible-cinema-0.9.7 lib/muter.rb
sensible-cinema-0.9.4 lib/muter.rb