add code from commit 8644 from codeplex sources

This commit is contained in:
gered 2012-05-29 11:06:41 -04:00
commit d365eb62e4
103 changed files with 5968 additions and 0 deletions

49
.gitattributes vendored Normal file
View file

@ -0,0 +1,49 @@
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
*.jpg binary
*.png binary
*.gif binary
*.cs text=auto diff=csharp
*.vb text=auto
*.c text=auto
*.cpp text=auto
*.cxx text=auto
*.h text=auto
*.hxx text=auto
*.py text=auto
*.rb text=auto
*.java text=auto
*.html text=auto
*.htm text=auto
*.css text=auto
*.scss text=auto
*.sass text=auto
*.less text=auto
*.js text=auto
*.lisp text=auto
*.clj text=auto
*.sql text=auto
*.php text=auto
*.lua text=auto
*.m text=auto
*.asm text=auto
*.erl text=auto
*.fs text=auto
*.fsx text=auto
*.hs text=auto
*.csproj text=auto merge=union
*.vbproj text=auto merge=union
*.fsproj text=auto merge=union
*.dbproj text=auto merge=union
*.sln text=auto eol=crlf merge=union

165
.gitignore vendored Normal file
View file

@ -0,0 +1,165 @@
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
**/[Dd]ebug/
**/[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
**/*.dotCover
## TODO: If you have NuGet Package Restore enabled, uncomment this
#**/packages/
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
# Visual Studio profiler
*.psess
*.vsp
# ReSharper is a .NET coding add-in
_ReSharper*
# Installshield output folder
[Ee]xpress
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish
# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
############
## Windows
############
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
# Mac crap
.DS_Store

20
AppleWirelessKeyboard.sln Normal file
View file

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppleWirelessKeyboard", "AppleWirelessKeyboard\AppleWirelessKeyboard.csproj", "{9654B149-302A-4392-8F91-4202FA6E0AE4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9654B149-302A-4392-8F91-4202FA6E0AE4}.Debug|x86.ActiveCfg = Debug|x86
{9654B149-302A-4392-8F91-4202FA6E0AE4}.Debug|x86.Build.0 = Debug|x86
{9654B149-302A-4392-8F91-4202FA6E0AE4}.Release|x86.ActiveCfg = Release|x86
{9654B149-302A-4392-8F91-4202FA6E0AE4}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,4 @@
<Application x:Class="AppleWirelessKeyboard.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Startup" Exit="Application_Exit"/>

View file

@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Diagnostics;
using System.Timers;
using System.Threading;
namespace AppleWirelessKeyboard
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
public static MainWindow Window { get; set; }
private void Application_Startup(object sender, StartupEventArgs e)
{
TrayIcon.Show();
uxsoft.VersionCheck();
if (!StartupShortcut.IsRegistered)
StartupShortcut.Register();
if (Process.GetProcessesByName(Application.ResourceAssembly.GetName().Name).Length > 1)
{
var processes = Process.GetProcessesByName(Application.ResourceAssembly.GetName().Name);
foreach (Process p in processes)
if (p != Process.GetCurrentProcess())
p.Kill();
}
Window = new MainWindow();
AppleKeyboardHID2.Start();
AppleKeyboardHID2.KeyDown += new AppleKeyboardHID2.AppleHIDKeyboardEventHandler(AppleKeyboardHID_KeyDown);
AppleKeyboardHID2.KeyUp += new AppleKeyboardHID2.AppleHIDKeyboardEventHandler(AppleKeyboardHID_KeyUp);
KeyboardListener.HookedKeys.Add(Key.F2);
KeyboardListener.HookedKeys.Add(Key.F3);
KeyboardListener.HookedKeys.Add(Key.F4);
KeyboardListener.HookedKeys.Add(Key.F7);
KeyboardListener.HookedKeys.Add(Key.F8);
KeyboardListener.HookedKeys.Add(Key.F9);
KeyboardListener.HookedKeys.Add(Key.F10);
KeyboardListener.HookedKeys.Add(Key.F11);
KeyboardListener.HookedKeys.Add(Key.F12);
KeyboardListener.HookedKeys.Add(Key.Back);
KeyboardListener.HookedKeys.Add(Key.Up);
KeyboardListener.HookedKeys.Add(Key.Left);
KeyboardListener.HookedKeys.Add(Key.Right);
KeyboardListener.HookedKeys.Add(Key.Down);
KeyboardListener.HookedKeys.Add(Key.Enter);
KeyboardListener.Register();
KeyboardListener.KeyDown += new KeyboardListener.KeyHookEventHandler(KeyboardListener_KeyDown);
Microsoft.Win32.SystemEvents.PowerModeChanged += new Microsoft.Win32.PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
}
void SystemEvents_PowerModeChanged(object sender, Microsoft.Win32.PowerModeChangedEventArgs e)
{
if (e.Mode == Microsoft.Win32.PowerModes.Resume)
{
Thread.Sleep(16000);
AppleKeyboardHID2.Shutdown();
AppleKeyboardHID2.Start();
}
}
void AppleKeyboardHID_KeyUp(AppleKeyboardSpecialKeys key)
{
if (key == AppleKeyboardSpecialKeys.Fn)
KeyboardListener.ModifierFn = false;
}
void AppleKeyboardHID_KeyDown(AppleKeyboardSpecialKeys key)
{
switch (key)
{
case AppleKeyboardSpecialKeys.Fn:
KeyboardListener.ModifierFn = true;
break;
case AppleKeyboardSpecialKeys.Eject:
KeyboardHandler.HandleEject();
break;
}
}
bool KeyboardListener_KeyDown(KeyboardListener.KeyHookEventArgs e)
{
return KeyboardHandler.HandleKeyDown(e);
}
private void Application_Exit(object sender, ExitEventArgs e)
{
KeyboardListener.UnRegister();
AppleKeyboardHID2.Shutdown();
}
}
}

View file

@ -0,0 +1,227 @@
using System;
using System.IO;
using AppleWirelessKeyboard;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
namespace AppleWirelessKeyboard
{
public class AppleKeyboardHID2
{
// Fields
static Stream _stream;
static bool CurrentPowerButtonIsDown;
public const int VIDApple = 0x5ac;
// Events
public static event EventHandler Disconnected;
public delegate void AppleHIDKeyboardEventHandler(AppleKeyboardSpecialKeys key);
public static event AppleHIDKeyboardEventHandler KeyUp;
public static event AppleHIDKeyboardEventHandler KeyDown;
//Properties
public static bool FnDown { get; set; }
public static bool EjectDown { get; set; }
public static bool PowerButtonDown { get; set; }
public static bool Registered
{
get { return _stream != null; }
}
public static void Shutdown()
{
if (_stream != null)
{
_stream.Close();
_stream = null;
}
}
private static void SpecialKeyStateChanged(IAsyncResult ar)
{
if ((_stream != null) && ar.IsCompleted)
{
try
{
_stream.EndRead(ar);
}
catch (OperationCanceledException)
{
}
catch (IOException)
{
if (Disconnected != null)
{
Disconnected(null, EventArgs.Empty);
}
return;
}
byte[] asyncState = ar.AsyncState as byte[];
byte[] buffer2 = asyncState;
for (int i = 0; i < buffer2.Length; i++)
{
byte num1 = buffer2[i];
}
if (asyncState[0] == 0x11)
{
switch (asyncState[1])
{
case 24:
{
EjectDown = true;
FnDown = true;
if (KeyDown != null)
KeyDown(AppleKeyboardSpecialKeys.Eject);
}
break;
case 16:
{
if (EjectDown)
{
EjectDown = false;
if (KeyUp != null)
KeyUp(AppleKeyboardSpecialKeys.Eject);
}
FnDown = true;
if (KeyDown != null)
KeyDown(AppleKeyboardSpecialKeys.Fn);
}
break;
case 8:
{
if (FnDown)
{
FnDown = false;
if (KeyUp != null)
KeyUp(AppleKeyboardSpecialKeys.Fn);
}
EjectDown = true;
if (KeyDown != null)
KeyDown(AppleKeyboardSpecialKeys.Eject);
}
break;
case 0:
{
if (EjectDown)
{
EjectDown = false;
if (KeyUp != null)
KeyUp(AppleKeyboardSpecialKeys.Eject);
}
if (FnDown)
{
FnDown = false;
if (KeyUp != null)
KeyUp(AppleKeyboardSpecialKeys.Fn);
}
}
break;
}
}
else if (asyncState[0] == 0x13)
{
CurrentPowerButtonIsDown = asyncState[1] == 1;
}
_stream.BeginRead(asyncState, 0, asyncState.Length, new AsyncCallback(SpecialKeyStateChanged), asyncState);
}
}
public static bool Start()
{
Guid guid;
HIDImports.SP_DEVICE_INTERFACE_DATA sp_device_interface_data = new HIDImports.SP_DEVICE_INTERFACE_DATA() { cbSize = Marshal.SizeOf(typeof(HIDImports.SP_DEVICE_INTERFACE_DATA)) };
if (_stream != null)
{
throw new InvalidOperationException("No Stream!");
}
HIDImports.HidD_GetHidGuid(out guid);
IntPtr hDevInfo = HIDImports.SetupDiGetClassDevs(ref guid, null, IntPtr.Zero, 0x10);
int num = 0;
while (HIDImports.SetupDiEnumDeviceInterfaces(hDevInfo, IntPtr.Zero, ref guid, num++, ref sp_device_interface_data))
{
uint num2;
HIDImports.SP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData = new HIDImports.SP_DEVICE_INTERFACE_DETAIL_DATA { cbSize = (IntPtr.Size == 8) ? (uint)8 : (uint)5 };
HIDImports.SetupDiGetDeviceInterfaceDetail(hDevInfo, ref sp_device_interface_data, IntPtr.Zero, 0, out num2, IntPtr.Zero);
if (HIDImports.SetupDiGetDeviceInterfaceDetail(hDevInfo, ref sp_device_interface_data, ref deviceInterfaceDetailData, num2, out num2, IntPtr.Zero))
{
HIDImports.HIDD_ATTRIBUTES hidd_attributes = new HIDImports.HIDD_ATTRIBUTES() { Size = Marshal.SizeOf(typeof(HIDImports.HIDD_ATTRIBUTES)) };
SafeFileHandle handle = HIDImports.CreateFile(deviceInterfaceDetailData.DevicePath, FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, HIDImports.EFileAttributes.Overlapped, IntPtr.Zero);
if (HIDImports.HidD_GetAttributes(handle.DangerousGetHandle(), ref hidd_attributes))
{
if (IsAppleWirelessKeyboard(hidd_attributes.VendorID, hidd_attributes.ProductID))
{
_stream = new FileStream(handle, FileAccess.ReadWrite, 0x16, true);
//break;
}
else
{
handle.Close();
}
}
}
}
HIDImports.SetupDiDestroyDeviceInfoList(hDevInfo);
if (_stream != null)
{
byte[] buffer = new byte[0x16];
_stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(SpecialKeyStateChanged), buffer);
return true;
}
return false;
}
private static bool IsAppleWirelessKeyboard(int vid, int pid)
{
if (vid == VIDApple)
{
Guid HIDGUID;
HIDImports.HidD_GetHidGuid(out HIDGUID);
IntPtr DeviceInfo = HIDImports.SetupDiGetClassDevs(ref HIDGUID, null, IntPtr.Zero, 16);
uint MemberIndex = 0;
HIDImports.SP_DEVINFO_DATA DID = new HIDImports.SP_DEVINFO_DATA() { cbSize = (uint)Marshal.SizeOf(typeof(HIDImports.SP_DEVINFO_DATA)) };
while (HIDImports.SetupDiEnumDeviceInfo(DeviceInfo, MemberIndex++, ref DID))
{
uint RequiredSize = 0;
uint PropertyDataType = 0;
IntPtr buffer = Marshal.AllocHGlobal(512);
string CLASS = "";
if (HIDImports.SetupDiGetDeviceRegistryProperty(DeviceInfo, ref DID, (uint)HIDImports.SPDRP.SPDRP_CLASS, out PropertyDataType, buffer, 512, out RequiredSize))
CLASS = Marshal.PtrToStringAuto(buffer);
if (CLASS.Equals("Keyboard", StringComparison.InvariantCultureIgnoreCase))
return true;
}
HIDImports.SetupDiDestroyDeviceInfoList(DeviceInfo);
return true;
}
else return false;
}
}
public enum AppleKeyboardSpecialKeys : byte
{
//Fn + Eject = 24
Fn = 16,
Eject = 8,
PowerButton = 3
//None = 0
}
}

View file

@ -0,0 +1,358 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9654B149-302A-4392-8F91-4202FA6E0AE4}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AppleWirelessKeyboard</RootNamespace>
<AssemblyName>AppleWirelessKeyboard</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<IsWebBootstrapper>true</IsWebBootstrapper>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
</SccLocalPath>
<SccAuxPath>
</SccAuxPath>
<SccProvider>
</SccProvider>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Web</InstallFrom>
<UpdateEnabled>true</UpdateEnabled>
<UpdateMode>Background</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<InstallUrl>http://applewirelesskbrd.codeplex.com/releases/clickonce/</InstallUrl>
<UpdateUrl>http://applewirelesskbrd.codeplex.com/releases/clickonce/</UpdateUrl>
<SupportUrl>http://applewirelesskbrd.codeplex.com</SupportUrl>
<ProductName>AppleWirelessKeyboard</ProductName>
<PublisherName>X-soft</PublisherName>
<SuiteName>AppleWirelessKeyboard</SuiteName>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.htm</WebPage>
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
<TrustUrlParameters>true</TrustUrlParameters>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>2.1.0.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>902A841B3FDD641CBAF24748EC3D69DFF5ECCF12</ManifestCertificateThumbprint>
</PropertyGroup>
<PropertyGroup>
<ManifestKeyFile>AppleWirelessKeyboard_TemporaryKey.pfx</ManifestKeyFile>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Gnome-Preferences-Desktop-Keyboard-Shortcuts.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<StartupObject>AppleWirelessKeyboard.App</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Remoting" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AppleKeyboardHID2.cs" />
<Compile Include="CoreAudioAPI\AudioEndpointVolume.cs" />
<Compile Include="CoreAudioAPI\AudioEndpointVolumeCallback.cs" />
<Compile Include="CoreAudioAPI\AudioEndpointVolumeChannel.cs" />
<Compile Include="CoreAudioAPI\AudioEndpointVolumeChannels.cs" />
<Compile Include="CoreAudioAPI\AudioEndpointVolumeNotificationDelegate.cs" />
<Compile Include="CoreAudioAPI\AudioEndpointVolumeStepInformation.cs" />
<Compile Include="CoreAudioAPI\AudioEndPointVolumeVolumeRange.cs" />
<Compile Include="CoreAudioAPI\AudioMeterInformation.cs" />
<Compile Include="CoreAudioAPI\AudioMeterInformationChannels.cs" />
<Compile Include="CoreAudioAPI\AudioSessionControl.cs" />
<Compile Include="CoreAudioAPI\AudioSessionDisconnectReason.cs" />
<Compile Include="CoreAudioAPI\AudioSessionManager.cs" />
<Compile Include="CoreAudioAPI\AudioSessionState.cs" />
<Compile Include="CoreAudioAPI\AudioVolumeNotificationData.cs" />
<Compile Include="CoreAudioAPI\AUDIO_VOLUME_NOTIFICATION_DATA.cs" />
<Compile Include="CoreAudioAPI\Blob.cs" />
<Compile Include="CoreAudioAPI\CLSCTX.cs" />
<Compile Include="CoreAudioAPI\EDataFlow.cs" />
<Compile Include="CoreAudioAPI\EDeviceState.cs" />
<Compile Include="CoreAudioAPI\EEndpointHardwareSupport.cs" />
<Compile Include="CoreAudioAPI\ERole.cs" />
<Compile Include="CoreAudioAPI\eStgmAccess.cs" />
<Compile Include="CoreAudioAPI\IAudioEndpointVolume.cs" />
<Compile Include="CoreAudioAPI\IAudioEndpointVolumeCallback.cs" />
<Compile Include="CoreAudioAPI\IAudioMeterInformation.cs" />
<Compile Include="CoreAudioAPI\IAudioPeakMeter.cs" />
<Compile Include="CoreAudioAPI\IAudioSessionControl2.cs" />
<Compile Include="CoreAudioAPI\IAudioSessionEnumerator.cs" />
<Compile Include="CoreAudioAPI\IAudioSessionEvents.cs" />
<Compile Include="CoreAudioAPI\IAudioSessionManager2.cs" />
<Compile Include="CoreAudioAPI\IMMDevice.cs" />
<Compile Include="CoreAudioAPI\IMMDeviceCollection.cs" />
<Compile Include="CoreAudioAPI\IMMDeviceEnumerator.cs" />
<Compile Include="CoreAudioAPI\IMMEndpoint.cs" />
<Compile Include="CoreAudioAPI\IPropertyStore.cs" />
<Compile Include="CoreAudioAPI\ISimpleAudioVolume.cs" />
<Compile Include="CoreAudioAPI\MMDevice.cs" />
<Compile Include="CoreAudioAPI\MMDeviceCollection.cs" />
<Compile Include="CoreAudioAPI\MMDeviceEnumerator.cs" />
<Compile Include="CoreAudioAPI\PKEY.cs" />
<Compile Include="CoreAudioAPI\PropertyKey.cs" />
<Compile Include="CoreAudioAPI\PropertyStore.cs" />
<Compile Include="CoreAudioAPI\PropertyStoreProperty.cs" />
<Compile Include="CoreAudioAPI\PropVariant.cs" />
<Compile Include="CoreAudioAPI\SessionCollection.cs" />
<Compile Include="CoreAudioAPI\SimpleAudioVolume.cs" />
<Compile Include="Glyphs\Eject.xaml.cs">
<DependentUpon>Eject.xaml</DependentUpon>
</Compile>
<Compile Include="Glyphs\MuteOff.xaml.cs">
<DependentUpon>MuteOff.xaml</DependentUpon>
</Compile>
<Compile Include="Glyphs\MuteOn.xaml.cs">
<DependentUpon>MuteOn.xaml</DependentUpon>
</Compile>
<Compile Include="Glyphs\Next.xaml.cs">
<DependentUpon>Next.xaml</DependentUpon>
</Compile>
<Compile Include="Glyphs\Off.xaml.cs">
<DependentUpon>Off.xaml</DependentUpon>
</Compile>
<Compile Include="Glyphs\On.xaml.cs">
<DependentUpon>On.xaml</DependentUpon>
</Compile>
<Compile Include="Glyphs\PlayPause.xaml.cs">
<DependentUpon>PlayPause.xaml</DependentUpon>
</Compile>
<Compile Include="Glyphs\Previous.xaml.cs">
<DependentUpon>Previous.xaml</DependentUpon>
</Compile>
<Compile Include="Glyphs\PrintScreen.xaml.cs">
<DependentUpon>PrintScreen.xaml</DependentUpon>
</Compile>
<Compile Include="Glyphs\TaskManager.xaml.cs">
<DependentUpon>TaskManager.xaml</DependentUpon>
</Compile>
<Compile Include="Glyphs\VolumeOff.xaml.cs">
<DependentUpon>VolumeOff.xaml</DependentUpon>
</Compile>
<Compile Include="Glyphs\VolumeOn.xaml.cs">
<DependentUpon>VolumeOn.xaml</DependentUpon>
</Compile>
<Compile Include="HIDImports.cs" />
<Compile Include="IoControl.cs" />
<Compile Include="iTunesControl.cs" />
<Compile Include="KeyboardControl.cs" />
<Compile Include="KeyboardHandler.cs" />
<Compile Include="KeyboardListener.cs" />
<Compile Include="NotificationCenter.cs" />
<Compile Include="PowerControl.cs" />
<Compile Include="PowerStatusBox.xaml.cs">
<DependentUpon>PowerStatusBox.xaml</DependentUpon>
</Compile>
<Compile Include="StartupShortcut.cs" />
<Compile Include="TrayIcon.cs" />
<Compile Include="uxsoft.cs" />
<Compile Include="Views\Configuration.xaml.cs">
<DependentUpon>Configuration.xaml</DependentUpon>
</Compile>
<Compile Include="VolumeControl.cs" />
<Page Include="Glyphs\Eject.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Glyphs\MuteOff.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Glyphs\MuteOn.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Glyphs\Next.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Glyphs\Off.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Glyphs\On.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Glyphs\PlayPause.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Glyphs\Previous.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Glyphs\PrintScreen.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Glyphs\TaskManager.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Glyphs\VolumeOff.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Glyphs\VolumeOn.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="PowerStatusBox.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Configuration.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="app.config" />
<None Include="AppleWirelessKeyboard_TemporaryKey.pfx" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Resource Include="Gnome-Preferences-Desktop-Keyboard-Shortcuts.ico" />
</ItemGroup>
<ItemGroup>
<COMReference Include="iTunesLib">
<Guid>{9E93C96F-CF0D-43F6-8BA8-B807A3370712}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>13</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>if /I "$(ConfigurationName)" == "Release" Eazfuscator.NET.exe "$(TargetPath)" --msbuild-project-path "$(ProjectPath)" --msbuild-project-configuration "$(ConfigurationName)" --msbuild-project-platform "$(PlatformName)" -n --newline-flush -v 2.9</PostBuildEvent>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,54 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace CoreAudioApi.Interfaces
{
internal struct AUDIO_VOLUME_NOTIFICATION_DATA
{
public Guid guidEventContext;
public bool bMuted;
public float fMasterVolume;
public uint nChannels;
public float ChannelVolume;
//Code Should Compile at warning level4 without any warnings,
//However this struct will give us Warning CS0649: Field [Fieldname]
//is never assigned to, and will always have its default value
//You can disable CS0649 in the project options but that will disable
//the warning for the whole project, it's a nice warning and we do want
//it in other places so we make a nice dummy function to keep the compiler
//happy.
private void FixCS0649()
{
guidEventContext = Guid.Empty;
bMuted = false;
fMasterVolume = 0;
nChannels = 0;
ChannelVolume = 0;
}
}
}

View file

@ -0,0 +1,65 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
public class AudioEndPointVolumeVolumeRange
{
float _VolumeMindB;
float _VolumeMaxdB;
float _VolumeIncrementdB;
internal AudioEndPointVolumeVolumeRange(IAudioEndpointVolume parent)
{
Marshal.ThrowExceptionForHR(parent.GetVolumeRange(out _VolumeMindB,out _VolumeMaxdB,out _VolumeIncrementdB));
}
public float MindB
{
get
{
return _VolumeMindB;
}
}
public float MaxdB
{
get
{
return _VolumeMaxdB;
}
}
public float IncrementdB
{
get
{
return _VolumeIncrementdB;
}
}
}
}

View file

@ -0,0 +1,157 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
public class AudioEndpointVolume : IDisposable
{
private IAudioEndpointVolume _AudioEndPointVolume;
private AudioEndpointVolumeChannels _Channels;
private AudioEndpointVolumeStepInformation _StepInformation;
private AudioEndPointVolumeVolumeRange _VolumeRange;
private EEndpointHardwareSupport _HardwareSupport;
private AudioEndpointVolumeCallback _CallBack;
public event AudioEndpointVolumeNotificationDelegate OnVolumeNotification;
public AudioEndPointVolumeVolumeRange VolumeRange
{
get
{
return _VolumeRange;
}
}
public EEndpointHardwareSupport HardwareSupport
{
get
{
return _HardwareSupport;
}
}
public AudioEndpointVolumeStepInformation StepInformation
{
get
{
return _StepInformation;
}
}
public AudioEndpointVolumeChannels Channels
{
get
{
return _Channels;
}
}
public float MasterVolumeLevel
{
get
{
float result;
Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetMasterVolumeLevel(out result));
return result;
}
set
{
Marshal.ThrowExceptionForHR(_AudioEndPointVolume.SetMasterVolumeLevel(value, Guid.Empty));
}
}
public float MasterVolumeLevelScalar
{
get
{
float result;
Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetMasterVolumeLevelScalar(out result));
return result;
}
set
{
Marshal.ThrowExceptionForHR(_AudioEndPointVolume.SetMasterVolumeLevelScalar(value, Guid.Empty));
}
}
public bool Mute
{
get
{
bool result;
Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetMute(out result));
return result;
}
set
{
Marshal.ThrowExceptionForHR(_AudioEndPointVolume.SetMute(value, Guid.Empty));
}
}
public void VolumeStepUp()
{
Marshal.ThrowExceptionForHR(_AudioEndPointVolume.VolumeStepUp(Guid.Empty));
}
public void VolumeStepDown()
{
Marshal.ThrowExceptionForHR(_AudioEndPointVolume.VolumeStepDown(Guid.Empty));
}
internal AudioEndpointVolume(IAudioEndpointVolume realEndpointVolume)
{
uint HardwareSupp;
_AudioEndPointVolume = realEndpointVolume;
_Channels = new AudioEndpointVolumeChannels(_AudioEndPointVolume);
_StepInformation = new AudioEndpointVolumeStepInformation(_AudioEndPointVolume);
Marshal.ThrowExceptionForHR(_AudioEndPointVolume.QueryHardwareSupport(out HardwareSupp));
_HardwareSupport = (EEndpointHardwareSupport)HardwareSupp;
_VolumeRange = new AudioEndPointVolumeVolumeRange(_AudioEndPointVolume);
_CallBack = new AudioEndpointVolumeCallback(this);
Marshal.ThrowExceptionForHR(_AudioEndPointVolume.RegisterControlChangeNotify( _CallBack));
}
internal void FireNotification(AudioVolumeNotificationData NotificationData)
{
AudioEndpointVolumeNotificationDelegate del = OnVolumeNotification;
if (del != null)
{
del(NotificationData);
}
}
#region IDisposable Members
public void Dispose()
{
if (_CallBack != null)
{
Marshal.ThrowExceptionForHR(_AudioEndPointVolume.UnregisterControlChangeNotify( _CallBack ));
_CallBack = null;
}
}
~AudioEndpointVolume()
{
Dispose();
}
#endregion
}
}

View file

@ -0,0 +1,73 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
// This class implements the IAudioEndpointVolumeCallback interface,
// it is implemented in this class because implementing it on AudioEndpointVolume
// (where the functionality is really wanted, would cause the OnNotify function
// to show up in the public API.
internal class AudioEndpointVolumeCallback : IAudioEndpointVolumeCallback
{
private AudioEndpointVolume _Parent;
internal AudioEndpointVolumeCallback(AudioEndpointVolume parent)
{
_Parent = parent;
}
[PreserveSig] public int OnNotify(IntPtr NotifyData)
{
//Since AUDIO_VOLUME_NOTIFICATION_DATA is dynamic in length based on the
//number of audio channels available we cannot just call PtrToStructure
//to get all data, thats why it is split up into two steps, first the static
//data is marshalled into the data structure, then with some IntPtr math the
//remaining floats are read from memory.
//
AUDIO_VOLUME_NOTIFICATION_DATA data = (AUDIO_VOLUME_NOTIFICATION_DATA) Marshal.PtrToStructure(NotifyData, typeof(AUDIO_VOLUME_NOTIFICATION_DATA));
//Determine offset in structure of the first float
IntPtr Offset = Marshal.OffsetOf(typeof(AUDIO_VOLUME_NOTIFICATION_DATA),"ChannelVolume");
//Determine offset in memory of the first float
IntPtr FirstFloatPtr = (IntPtr)((long)NotifyData + (long)Offset);
float[] voldata = new float[data.nChannels];
//Read all floats from memory.
for (int i = 0; i < data.nChannels; i++)
{
voldata[i] = (float)Marshal.PtrToStructure(FirstFloatPtr, typeof(float));
}
//Create combined structure and Fire Event in parent class.
AudioVolumeNotificationData NotificationData = new AudioVolumeNotificationData(data.guidEventContext, data.bMuted, data.fMasterVolume, voldata);
_Parent.FireNotification(NotificationData);
return 0; //S_OK
}
}
}

View file

@ -0,0 +1,71 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
public class AudioEndpointVolumeChannel
{
private uint _Channel;
private IAudioEndpointVolume _AudioEndpointVolume;
internal AudioEndpointVolumeChannel(IAudioEndpointVolume parent, int channel)
{
_Channel = (uint)channel;
_AudioEndpointVolume = parent;
}
public float VolumeLevel
{
get
{
float result;
Marshal.ThrowExceptionForHR(_AudioEndpointVolume.GetChannelVolumeLevel(_Channel,out result));
return result;
}
set
{
Marshal.ThrowExceptionForHR(_AudioEndpointVolume.SetChannelVolumeLevel(_Channel, value,Guid.Empty));
}
}
public float VolumeLevelScalar
{
get
{
float result;
Marshal.ThrowExceptionForHR(_AudioEndpointVolume.GetChannelVolumeLevelScalar(_Channel, out result));
return result;
}
set
{
Marshal.ThrowExceptionForHR(_AudioEndpointVolume.SetChannelVolumeLevelScalar(_Channel, value, Guid.Empty));
}
}
}
}

View file

@ -0,0 +1,68 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
public class AudioEndpointVolumeChannels
{
IAudioEndpointVolume _AudioEndPointVolume;
AudioEndpointVolumeChannel[] _Channels;
public int Count
{
get
{
int result;
Marshal.ThrowExceptionForHR(_AudioEndPointVolume.GetChannelCount(out result));
return result;
}
}
public AudioEndpointVolumeChannel this[int index]
{
get
{
return _Channels[index];
}
}
internal AudioEndpointVolumeChannels(IAudioEndpointVolume parent)
{
int ChannelCount;
_AudioEndPointVolume = parent;
ChannelCount = Count;
_Channels = new AudioEndpointVolumeChannel[ChannelCount];
for (int i = 0; i < ChannelCount; i++)
{
_Channels[i] = new AudioEndpointVolumeChannel(_AudioEndPointVolume, i);
}
}
}
}

View file

@ -0,0 +1,30 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace CoreAudioApi
{
public delegate void AudioEndpointVolumeNotificationDelegate( AudioVolumeNotificationData data);
}

View file

@ -0,0 +1,56 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
public class AudioEndpointVolumeStepInformation
{
private uint _Step;
private uint _StepCount;
internal AudioEndpointVolumeStepInformation(IAudioEndpointVolume parent)
{
Marshal.ThrowExceptionForHR(parent.GetVolumeStepInfo(out _Step, out _StepCount));
}
public uint Step
{
get
{
return _Step;
}
}
public uint StepCount
{
get
{
return _StepCount;
}
}
}
}

View file

@ -0,0 +1,79 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
public class AudioMeterInformation
{
private IAudioMeterInformation _AudioMeterInformation;
private EEndpointHardwareSupport _HardwareSupport;
private AudioMeterInformationChannels _Channels;
internal AudioMeterInformation(IAudioMeterInformation realInterface)
{
int HardwareSupp;
_AudioMeterInformation = realInterface;
Marshal.ThrowExceptionForHR(_AudioMeterInformation.QueryHardwareSupport(out HardwareSupp));
_HardwareSupport = (EEndpointHardwareSupport)HardwareSupp;
_Channels = new AudioMeterInformationChannels(_AudioMeterInformation);
}
public AudioMeterInformationChannels PeakValues
{
get
{
return _Channels;
}
}
public EEndpointHardwareSupport HardwareSupport
{
get
{
return _HardwareSupport;
}
}
public float MasterPeakValue
{
get
{
float result;
Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetPeakValue(out result));
return result;
}
}
}
}

View file

@ -0,0 +1,61 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
public class AudioMeterInformationChannels
{
IAudioMeterInformation _AudioMeterInformation;
public int Count
{
get
{
int result;
Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetMeteringChannelCount(out result));
return result;
}
}
public float this[int index]
{
get
{
float[] peakValues = new float[Count];
GCHandle Params = GCHandle.Alloc(peakValues, GCHandleType.Pinned);
Marshal.ThrowExceptionForHR(_AudioMeterInformation.GetChannelsPeakValues(peakValues.Length, Params.AddrOfPinnedObject()));
Params.Free();
return peakValues[index];
}
}
internal AudioMeterInformationChannels(IAudioMeterInformation parent)
{
_AudioMeterInformation = parent;
}
}
}

View file

@ -0,0 +1,155 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
public class AudioSessionControl
{
internal IAudioSessionControl2 _AudioSessionControl;
internal AudioMeterInformation _AudioMeterInformation;
internal SimpleAudioVolume _SimpleAudioVolume;
public AudioMeterInformation AudioMeterInformation
{
get
{
return _AudioMeterInformation;
}
}
public SimpleAudioVolume SimpleAudioVolume
{
get
{
return _SimpleAudioVolume;
}
}
internal AudioSessionControl(IAudioSessionControl2 realAudioSessionControl)
{
IAudioMeterInformation _meters = realAudioSessionControl as IAudioMeterInformation;
ISimpleAudioVolume _volume = realAudioSessionControl as ISimpleAudioVolume;
if (_meters != null)
_AudioMeterInformation = new CoreAudioApi.AudioMeterInformation(_meters);
if (_volume != null)
_SimpleAudioVolume = new SimpleAudioVolume(_volume);
_AudioSessionControl = realAudioSessionControl;
}
public void RegisterAudioSessionNotification(IAudioSessionEvents eventConsumer)
{
Marshal.ThrowExceptionForHR(_AudioSessionControl.RegisterAudioSessionNotification(eventConsumer));
}
public void UnregisterAudioSessionNotification(IAudioSessionEvents eventConsumer)
{
Marshal.ThrowExceptionForHR(_AudioSessionControl.UnregisterAudioSessionNotification(eventConsumer));
}
public AudioSessionState State
{
get
{
AudioSessionState res;
Marshal.ThrowExceptionForHR(_AudioSessionControl.GetState(out res));
return res;
}
}
public string DisplayName
{
get
{
IntPtr NamePtr;
Marshal.ThrowExceptionForHR(_AudioSessionControl.GetDisplayName(out NamePtr));
string res = Marshal.PtrToStringAuto(NamePtr);
Marshal.FreeCoTaskMem(NamePtr);
return res;
}
}
public string IconPath
{
get
{
IntPtr NamePtr;
Marshal.ThrowExceptionForHR(_AudioSessionControl.GetIconPath(out NamePtr));
string res = Marshal.PtrToStringAuto(NamePtr);
Marshal.FreeCoTaskMem(NamePtr);
return res;
}
}
public string SessionIdentifier
{
get
{
IntPtr NamePtr;
Marshal.ThrowExceptionForHR(_AudioSessionControl.GetSessionIdentifier(out NamePtr));
string res = Marshal.PtrToStringAuto(NamePtr);
Marshal.FreeCoTaskMem(NamePtr);
return res;
}
}
public string SessionInstanceIdentifier
{
get
{
IntPtr NamePtr;
Marshal.ThrowExceptionForHR(_AudioSessionControl.GetSessionInstanceIdentifier(out NamePtr));
string res = Marshal.PtrToStringAuto(NamePtr);
Marshal.FreeCoTaskMem(NamePtr);
return res;
}
}
public uint ProcessID
{
get
{
uint pid;
Marshal.ThrowExceptionForHR(_AudioSessionControl.GetProcessId(out pid));
return pid;
}
}
public bool IsSystemIsSystemSoundsSession
{
get
{
return (_AudioSessionControl.IsSystemSoundsSession() == 0); //S_OK
}
}
}
}

View file

@ -0,0 +1,38 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CoreAudioApi
{
public enum AudioSessionDisconnectReason
{
DisconnectReasonDeviceRemoval = 0,
DisconnectReasonServerShutdown = (DisconnectReasonDeviceRemoval + 1),
DisconnectReasonFormatChanged = (DisconnectReasonServerShutdown + 1),
DisconnectReasonSessionLogoff = (DisconnectReasonFormatChanged + 1),
DisconnectReasonSessionDisconnected = (DisconnectReasonSessionLogoff + 1),
DisconnectReasonExclusiveModeOverride = (DisconnectReasonSessionDisconnected + 1)
}
}

View file

@ -0,0 +1,54 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
public class AudioSessionManager
{
private IAudioSessionManager2 _AudioSessionManager;
private SessionCollection _Sessions;
internal AudioSessionManager(IAudioSessionManager2 realAudioSessionManager)
{
_AudioSessionManager = realAudioSessionManager;
IAudioSessionEnumerator _SessionEnum ;
Marshal.ThrowExceptionForHR(_AudioSessionManager.GetSessionEnumerator(out _SessionEnum));
_Sessions = new SessionCollection(_SessionEnum);
}
public SessionCollection Sessions
{
get
{
return _Sessions;
}
}
}
}

View file

@ -0,0 +1,35 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CoreAudioApi
{
public enum AudioSessionState
{
AudioSessionStateInactive = 0,
AudioSessionStateActive = 1,
AudioSessionStateExpired = 2
}
}

View file

@ -0,0 +1,83 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace CoreAudioApi
{
public class AudioVolumeNotificationData
{
private Guid _EventContext;
private bool _Muted;
private float _MasterVolume;
private int _Channels;
private float[] _ChannelVolume;
public Guid EventContext
{
get
{
return _EventContext;
}
}
public bool Muted
{
get
{
return _Muted;
}
}
public float MasterVolume
{
get
{
return _MasterVolume;
}
}
public int Channels
{
get
{
return _Channels;
}
}
public float[] ChannelVolume
{
get
{
return _ChannelVolume;
}
}
public AudioVolumeNotificationData(Guid eventContext, bool muted, float masterVolume, float[] channelVolume)
{
_EventContext = eventContext;
_Muted = muted;
_MasterVolume = masterVolume;
_Channels = channelVolume.Length;
_ChannelVolume = channelVolume;
}
}
}

View file

@ -0,0 +1,47 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
internal struct Blob
{
public int Length;
public IntPtr Data;
//Code Should Compile at warning level4 without any warnings,
//However this struct will give us Warning CS0649: Field [Fieldname]
//is never assigned to, and will always have its default value
//You can disable CS0649 in the project options but that will disable
//the warning for the whole project, it's a nice warning and we do want
//it in other places so we make a nice dummy function to keep the compiler
//happy.
private void FixCS0649()
{
Length = 0;
Data = IntPtr.Zero;
}
}
}

View file

@ -0,0 +1,53 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace CoreAudioApi.Interfaces
{
[Flags]
internal enum CLSCTX : uint
{
INPROC_SERVER = 0x1,
INPROC_HANDLER = 0x2,
LOCAL_SERVER = 0x4,
INPROC_SERVER16 = 0x8,
REMOTE_SERVER = 0x10,
INPROC_HANDLER16 = 0x20,
RESERVED1 = 0x40,
RESERVED2 = 0x80,
RESERVED3 = 0x100,
RESERVED4 = 0x200,
NO_CODE_DOWNLOAD = 0x400,
RESERVED5 = 0x800,
NO_CUSTOM_MARSHAL = 0x1000,
ENABLE_CODE_DOWNLOAD = 0x2000,
NO_FAILURE_LOG = 0x4000,
DISABLE_AAA = 0x8000,
ENABLE_AAA = 0x10000,
FROM_DEFAULT_CONTEXT = 0x20000,
INPROC = INPROC_SERVER | INPROC_HANDLER,
SERVER = INPROC_SERVER | LOCAL_SERVER | REMOTE_SERVER,
ALL = SERVER | INPROC_HANDLER
}
}

View file

@ -0,0 +1,35 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace CoreAudioApi
{
public enum EDataFlow
{
eRender = 0,
eCapture = 1,
eAll = 2 ,
EDataFlow_enum_count =3
}
}

View file

@ -0,0 +1,36 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace CoreAudioApi
{
[Flags]
public enum EDeviceState : uint
{
DEVICE_STATE_ACTIVE = 0x00000001,
DEVICE_STATE_UNPLUGGED = 0x00000002,
DEVICE_STATE_NOTPRESENT = 0x00000004,
DEVICE_STATEMASK_ALL = 0x00000007
}
}

View file

@ -0,0 +1,35 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace CoreAudioApi
{
[Flags]
public enum EEndpointHardwareSupport
{
Volume = 0x00000001,
Mute = 0x00000002,
Meter = 0x00000004
}
}

View file

@ -0,0 +1,35 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace CoreAudioApi
{
public enum ERole
{
eConsole =0,
eMultimedia =1,
eCommunications=2,
ERole_enum_count=3
}
}

View file

@ -0,0 +1,70 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("5CDF2C82-841E-4546-9722-0CF74078229A"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IAudioEndpointVolume
{
[PreserveSig]
int RegisterControlChangeNotify(IAudioEndpointVolumeCallback pNotify);
[PreserveSig]
int UnregisterControlChangeNotify(IAudioEndpointVolumeCallback pNotify);
[PreserveSig]
int GetChannelCount(out int pnChannelCount);
[PreserveSig]
int SetMasterVolumeLevel(float fLevelDB, Guid pguidEventContext);
[PreserveSig]
int SetMasterVolumeLevelScalar(float fLevel, Guid pguidEventContext);
[PreserveSig]
int GetMasterVolumeLevel(out float pfLevelDB);
[PreserveSig]
int GetMasterVolumeLevelScalar(out float pfLevel);
[PreserveSig]
int SetChannelVolumeLevel(uint nChannel, float fLevelDB, Guid pguidEventContext);
[PreserveSig]
int SetChannelVolumeLevelScalar(uint nChannel, float fLevel, Guid pguidEventContext);
[PreserveSig]
int GetChannelVolumeLevel(uint nChannel, out float pfLevelDB);
[PreserveSig]
int GetChannelVolumeLevelScalar(uint nChannel, out float pfLevel);
[PreserveSig]
int SetMute([MarshalAs(UnmanagedType.Bool)] Boolean bMute, Guid pguidEventContext);
[PreserveSig]
int GetMute(out bool pbMute);
[PreserveSig]
int GetVolumeStepInfo(out uint pnStep, out uint pnStepCount);
[PreserveSig]
int VolumeStepUp(Guid pguidEventContext);
[PreserveSig]
int VolumeStepDown(Guid pguidEventContext);
[PreserveSig]
int QueryHardwareSupport(out uint pdwHardwareSupportMask);
[PreserveSig]
int GetVolumeRange(out float pflVolumeMindB, out float pflVolumeMaxdB, out float pflVolumeIncrementdB);
}
}

View file

@ -0,0 +1,36 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("657804FA-D6AD-4496-8A60-352752AF4F89"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IAudioEndpointVolumeCallback
{
[PreserveSig] int OnNotify(IntPtr pNotifyData);
};
}

View file

@ -0,0 +1,42 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IAudioMeterInformation
{
[PreserveSig]
int GetPeakValue(out float pfPeak);
[PreserveSig]
int GetMeteringChannelCount(out int pnChannelCount);
[PreserveSig]
int GetChannelsPeakValues( int u32ChannelCount,[In] IntPtr afPeakValues);
[PreserveSig]
int QueryHardwareSupport( out int pdwHardwareSupportMask);
};
}

View file

@ -0,0 +1,37 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("DD79923C-0599-45e0-B8B6-C8DF7DB6E796"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IAudioPeakMeter
{
int GetChannelCount( out int pcChannels);
int GetLevel( int Channel, out float level);
}
}

View file

@ -0,0 +1,66 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("bfb7ff88-7239-4fc9-8fa2-07c950be9c6d"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IAudioSessionControl2
{
//IAudioSession functions
[PreserveSig]
int GetState(out AudioSessionState state);
[PreserveSig]
int GetDisplayName(out IntPtr name);
[PreserveSig]
int SetDisplayName(string value, Guid EventContext);
[PreserveSig]
int GetIconPath(out IntPtr Path);
[PreserveSig]
int SetIconPath(string Value, Guid EventContext);
[PreserveSig]
int GetGroupingParam(out Guid GroupingParam);
[PreserveSig]
int SetGroupingParam(Guid Override, Guid Eventcontext);
[PreserveSig]
int RegisterAudioSessionNotification(IAudioSessionEvents NewNotifications);
[PreserveSig]
int UnregisterAudioSessionNotification(IAudioSessionEvents NewNotifications);
//IAudioSession2 functions
[PreserveSig]
int GetSessionIdentifier( out IntPtr retVal);
[PreserveSig]
int GetSessionInstanceIdentifier( out IntPtr retVal);
[PreserveSig]
int GetProcessId( out UInt32 retvVal);
[PreserveSig]
int IsSystemSoundsSession();
[PreserveSig]
int SetDuckingPreference( bool optOut);
}
}

View file

@ -0,0 +1,34 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System.Runtime.InteropServices;
using System;
namespace CoreAudioApi.Interfaces
{
[Guid("E2F5BB11-0570-40CA-ACDD-3AA01277DEE8"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IAudioSessionEnumerator
{
int GetCount( out int SessionCount);
int GetSession( int SessionCount,out IAudioSessionControl2 Session );
}
}

View file

@ -0,0 +1,48 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("24918ACC-64B3-37C1-8CA9-74A66E9957A8"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IAudioSessionEvents
{
[PreserveSig]
int OnDisplayNameChanged( [MarshalAs(UnmanagedType.LPWStr)] string NewDisplayName, Guid EventContext );
[PreserveSig]
int OnIconPathChanged( [MarshalAs(UnmanagedType.LPWStr)] string NewIconPath, Guid EventContext );
[PreserveSig]
int OnSimpleVolumeChanged( float NewVolume,bool newMute, Guid EventContext );
[PreserveSig]
int OnChannelVolumeChanged( UInt32 ChannelCount, IntPtr NewChannelVolumeArray, UInt32 ChangedChannel, Guid EventContext );
[PreserveSig]
int OnGroupingParamChanged( Guid NewGroupingParam, Guid EventContext );
[PreserveSig]
int OnStateChanged( AudioSessionState NewState);
[PreserveSig]
int OnSessionDisconnected( AudioSessionDisconnectReason DisconnectReason);
}
}

View file

@ -0,0 +1,49 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IAudioSessionManager2
{
[PreserveSig]
int GetAudioSessionControl(ref Guid AudioSessionGuid, UInt32 StreamFlags, IntPtr ISessionControl );
[PreserveSig]
int GetSimpleAudioVolume(ref Guid AudioSessionGuid, UInt32 StreamFlags, IntPtr /*ISimpleAudioVolume*/ SimpleAudioVolume);
[PreserveSig]
int GetSessionEnumerator(out IAudioSessionEnumerator SessionEnum);
[PreserveSig]
int RegisterSessionNotification( IntPtr IAudioSessionNotification );
[PreserveSig]
int UnregisterSessionNotification( IntPtr IAudioSessionNotification );
[PreserveSig]
int RegisterDuckNotification( string sessionID, IntPtr IAudioVolumeDuckNotification);
[PreserveSig]
int UnregisterDuckNotification(IntPtr IAudioVolumeDuckNotification);
};
}

View file

@ -0,0 +1,42 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("D666063F-1587-4E43-81F1-B948E807363F"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IMMDevice
{
[PreserveSig]
int Activate(ref Guid iid, CLSCTX dwClsCtx, IntPtr pActivationParams, [MarshalAs(UnmanagedType.IUnknown)] out object ppInterface);
[PreserveSig]
int OpenPropertyStore(EStgmAccess stgmAccess, out IPropertyStore propertyStore);
[PreserveSig]
int GetId([MarshalAs(UnmanagedType.LPWStr)] out string ppstrId);
[PreserveSig]
int GetState(out EDeviceState pdwState);
}
}

View file

@ -0,0 +1,38 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("0BD7A1BE-7A1A-44DB-8397-CC5392387B5E"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IMMDeviceCollection
{
[PreserveSig]
int GetCount(out uint pcDevices);
[PreserveSig]
int Item(uint nDevice, out IMMDevice Device);
}
}

View file

@ -0,0 +1,44 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("A95664D2-9614-4F35-A746-DE8DB63617E6"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IMMDeviceEnumerator
{
[PreserveSig]
int EnumAudioEndpoints(EDataFlow dataFlow, EDeviceState StateMask, out IMMDeviceCollection device);
[PreserveSig]
int GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role, out IMMDevice ppEndpoint);
[PreserveSig]
int GetDevice(string pwstrId, out IMMDevice ppDevice);
[PreserveSig]
int RegisterEndpointNotificationCallback(IntPtr pClient);
[PreserveSig]
int UnregisterEndpointNotificationCallback(IntPtr pClient);
}
}

View file

@ -0,0 +1,36 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("1BE09788-6894-4089-8586-9A2A6C265AC5"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IMMEndpoint
{
[PreserveSig]
int GetDataFlow(out EDataFlow pDataFlow);
};
}

View file

@ -0,0 +1,44 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IPropertyStore
{
[PreserveSig]
int GetCount( out Int32 count);
[PreserveSig]
int GetAt( int iProp, out PropertyKey pkey);
[PreserveSig]
int GetValue(ref PropertyKey key, out PropVariant pv);
[PreserveSig]
int SetValue(ref PropertyKey key, ref PropVariant propvar);
[PreserveSig]
int Commit( );
};
}

View file

@ -0,0 +1,43 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace CoreAudioApi.Interfaces
{
[Guid("87CE5498-68D6-44E5-9215-6DA47EF883D8"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface ISimpleAudioVolume
{
[PreserveSig]
int SetMasterVolume( float fLevel,ref Guid EventContext);
[PreserveSig]
int GetMasterVolume( out float pfLevel);
[PreserveSig]
int SetMute( bool bMute, ref Guid EventContext) ;
[PreserveSig]
int GetMute( out bool bMute);
}
}

View file

@ -0,0 +1,180 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
public class MMDevice
{
#region Variables
private IMMDevice _RealDevice;
private PropertyStore _PropertyStore;
private AudioMeterInformation _AudioMeterInformation;
private AudioEndpointVolume _AudioEndpointVolume;
private AudioSessionManager _AudioSessionManager;
#endregion
#region Guids
private static Guid IID_IAudioMeterInformation = typeof(IAudioMeterInformation).GUID;
private static Guid IID_IAudioEndpointVolume = typeof(IAudioEndpointVolume).GUID;
private static Guid IID_IAudioSessionManager = typeof(IAudioSessionManager2).GUID;
#endregion
#region Init
private void GetPropertyInformation()
{
IPropertyStore propstore;
Marshal.ThrowExceptionForHR(_RealDevice.OpenPropertyStore(EStgmAccess.STGM_READ, out propstore));
_PropertyStore = new PropertyStore(propstore);
}
private void GetAudioSessionManager()
{
object result;
Marshal.ThrowExceptionForHR(_RealDevice.Activate(ref IID_IAudioSessionManager, CLSCTX.ALL, IntPtr.Zero, out result));
_AudioSessionManager = new AudioSessionManager(result as IAudioSessionManager2);
}
private void GetAudioMeterInformation()
{
object result;
Marshal.ThrowExceptionForHR( _RealDevice.Activate(ref IID_IAudioMeterInformation, CLSCTX.ALL, IntPtr.Zero, out result));
_AudioMeterInformation = new AudioMeterInformation( result as IAudioMeterInformation);
}
private void GetAudioEndpointVolume()
{
object result;
Marshal.ThrowExceptionForHR(_RealDevice.Activate(ref IID_IAudioEndpointVolume, CLSCTX.ALL, IntPtr.Zero, out result));
_AudioEndpointVolume = new AudioEndpointVolume(result as IAudioEndpointVolume);
}
#endregion
#region Properties
public AudioSessionManager AudioSessionManager
{
get
{
if (_AudioSessionManager == null)
GetAudioSessionManager();
return _AudioSessionManager;
}
}
public AudioMeterInformation AudioMeterInformation
{
get
{
if (_AudioMeterInformation == null)
GetAudioMeterInformation();
return _AudioMeterInformation;
}
}
public AudioEndpointVolume AudioEndpointVolume
{
get
{
if (_AudioEndpointVolume == null)
GetAudioEndpointVolume();
return _AudioEndpointVolume;
}
}
public PropertyStore Properties
{
get
{
if (_PropertyStore == null)
GetPropertyInformation();
return _PropertyStore;
}
}
public string FriendlyName
{
get
{
if (_PropertyStore == null)
GetPropertyInformation();
if (_PropertyStore.Contains(PKEY.PKEY_DeviceInterface_FriendlyName))
{
return (string)_PropertyStore[PKEY.PKEY_DeviceInterface_FriendlyName].Value;
}
else
return "Unknown";
}
}
public string ID
{
get
{
string Result;
Marshal.ThrowExceptionForHR(_RealDevice.GetId(out Result));
return Result;
}
}
public EDataFlow DataFlow
{
get
{
EDataFlow Result;
IMMEndpoint ep = _RealDevice as IMMEndpoint ;
ep.GetDataFlow(out Result);
return Result;
}
}
public EDeviceState State
{
get
{
EDeviceState Result;
Marshal.ThrowExceptionForHR(_RealDevice.GetState(out Result));
return Result;
}
}
#endregion
#region Constructor
internal MMDevice(IMMDevice realDevice)
{
_RealDevice = realDevice;
}
#endregion
}
}

View file

@ -0,0 +1,59 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using CoreAudioApi.Interfaces;
namespace CoreAudioApi
{
public class MMDeviceCollection
{
private IMMDeviceCollection _MMDeviceCollection;
public int Count
{
get
{
uint result;
Marshal.ThrowExceptionForHR(_MMDeviceCollection.GetCount(out result));
return (int)result;
}
}
public MMDevice this[int index]
{
get
{
IMMDevice result;
_MMDeviceCollection.Item((uint)index, out result);
return new MMDevice(result);
}
}
internal MMDeviceCollection(IMMDeviceCollection parent)
{
_MMDeviceCollection = parent;
}
}
}

View file

@ -0,0 +1,70 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using CoreAudioApi.Interfaces;
namespace CoreAudioApi
{
//Marked as internal, since on its own its no good
[ComImport, Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")]
internal class _MMDeviceEnumerator
{
}
//Small wrapper class
public class MMDeviceEnumerator
{
private IMMDeviceEnumerator _realEnumerator = new _MMDeviceEnumerator() as IMMDeviceEnumerator;
public MMDeviceCollection EnumerateAudioEndPoints(EDataFlow dataFlow, EDeviceState dwStateMask)
{
IMMDeviceCollection result;
Marshal.ThrowExceptionForHR(_realEnumerator.EnumAudioEndpoints(dataFlow,dwStateMask,out result));
return new MMDeviceCollection(result);
}
public MMDevice GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role)
{
IMMDevice _Device = null;
Marshal.ThrowExceptionForHR(((IMMDeviceEnumerator)_realEnumerator).GetDefaultAudioEndpoint(dataFlow, role, out _Device));
return new MMDevice(_Device);
}
public MMDevice GetDevice(string ID)
{
IMMDevice _Device = null;
Marshal.ThrowExceptionForHR(((IMMDeviceEnumerator)_realEnumerator).GetDevice(ID, out _Device));
return new MMDevice(_Device);
}
public MMDeviceEnumerator()
{
if (System.Environment.OSVersion.Version.Major < 6)
{
throw new NotSupportedException("This functionality is only supported on Windows Vista or newer.");
}
}
}
}

View file

@ -0,0 +1,41 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace CoreAudioApi
{
public static class PKEY
{
public static readonly Guid PKEY_DeviceInterface_FriendlyName = new Guid( 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0);
public static readonly Guid PKEY_AudioEndpoint_FormFactor = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
public static readonly Guid PKEY_AudioEndpoint_ControlPanelPageProvider = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
public static readonly Guid PKEY_AudioEndpoint_Association = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
public static readonly Guid PKEY_AudioEndpoint_PhysicalSpeakers = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
public static readonly Guid PKEY_AudioEndpoint_GUID = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
public static readonly Guid PKEY_AudioEndpoint_Disable_SysFx = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
public static readonly Guid PKEY_AudioEndpoint_FullRangeSpeakers = new Guid( 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x0e);
public static readonly Guid PKEY_AudioEngine_DeviceFormat = new Guid(0xf19f064d, 0x82c, 0x4e27, 0xbc, 0x73, 0x68, 0x82, 0xa1, 0xbb, 0x8e, 0x4c);
}
}

View file

@ -0,0 +1,96 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices.ComTypes;
using System.Runtime.InteropServices;
using CoreAudioApi.Interfaces;
namespace CoreAudioApi
{
[StructLayout(LayoutKind.Explicit)]
public struct PropVariant
{
[FieldOffset(0)] short vt;
[FieldOffset(2)] short wReserved1;
[FieldOffset(4)] short wReserved2;
[FieldOffset(6)] short wReserved3;
[FieldOffset(8)] sbyte cVal;
[FieldOffset(8)] byte bVal;
[FieldOffset(8)] short iVal;
[FieldOffset(8)] ushort uiVal;
[FieldOffset(8)] int lVal;
[FieldOffset(8)] uint ulVal;
[FieldOffset(8)] long hVal;
[FieldOffset(8)] ulong uhVal;
[FieldOffset(8)] float fltVal;
[FieldOffset(8)] double dblVal;
[FieldOffset(8)] Blob blobVal;
[FieldOffset(8)] DateTime date;
[FieldOffset(8)] bool boolVal;
[FieldOffset(8)] int scode;
[FieldOffset(8)] System.Runtime.InteropServices.ComTypes.FILETIME filetime;
[FieldOffset(8)] IntPtr everything_else;
//I'm sure there is a more efficient way to do this but this works ..for now..
internal byte[] GetBlob()
{
byte[] Result = new byte[blobVal.Length];
for (int i = 0; i < blobVal.Length; i++)
{
Result[i] = Marshal.ReadByte((IntPtr) ((long)(blobVal.Data) + i));
}
return Result;
}
public object Value
{
get
{
VarEnum ve = (VarEnum)vt;
switch (ve)
{
case VarEnum.VT_I1:
return bVal;
case VarEnum.VT_I2:
return iVal;
case VarEnum.VT_I4:
return lVal;
case VarEnum.VT_I8:
return hVal;
case VarEnum.VT_INT:
return iVal;
case VarEnum.VT_UI4:
return ulVal;
case VarEnum.VT_LPWSTR:
return Marshal.PtrToStringUni(everything_else);
case VarEnum.VT_BLOB:
return GetBlob();
}
return "FIXME Type = " + ve.ToString();
}
}
}
}

View file

@ -0,0 +1,34 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace CoreAudioApi
{
public struct PropertyKey
{
public Guid fmtid;
public int pid;
};
}

View file

@ -0,0 +1,107 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
/// <summary>
/// Property Store class, only supports reading properties at the moment.
/// </summary>
public class PropertyStore
{
private IPropertyStore _Store;
public int Count
{
get
{
int Result;
Marshal.ThrowExceptionForHR(_Store.GetCount(out Result));
return Result;
}
}
public PropertyStoreProperty this[int index]
{
get
{
PropVariant result;
PropertyKey key = Get(index);
Marshal.ThrowExceptionForHR(_Store.GetValue(ref key, out result));
return new PropertyStoreProperty(key, result);
}
}
public bool Contains(Guid guid)
{
for (int i = 0; i < Count; i++)
{
PropertyKey key = Get(i);
if (key.fmtid == guid)
return true;
}
return false;
}
public PropertyStoreProperty this[Guid guid]
{
get
{
PropVariant result;
for (int i = 0; i < Count; i++)
{
PropertyKey key = Get(i);
if (key.fmtid == guid)
{
Marshal.ThrowExceptionForHR(_Store.GetValue(ref key, out result));
return new PropertyStoreProperty(key, result);
}
}
return null;
}
}
public PropertyKey Get(int index)
{
PropertyKey key;
Marshal.ThrowExceptionForHR( _Store.GetAt(index, out key));
return key;
}
public PropVariant GetValue(int index)
{
PropVariant result;
PropertyKey key = Get(index);
Marshal.ThrowExceptionForHR(_Store.GetValue(ref key, out result));
return result;
}
internal PropertyStore(IPropertyStore store)
{
_Store = store;
}
}
}

View file

@ -0,0 +1,57 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
using CoreAudioApi.Interfaces;
namespace CoreAudioApi
{
public class PropertyStoreProperty
{
private PropertyKey _PropertyKey;
private PropVariant _PropValue;
internal PropertyStoreProperty(PropertyKey key, PropVariant value)
{
_PropertyKey = key;
_PropValue = value;
}
public PropertyKey Key
{
get
{
return _PropertyKey;
}
}
public object Value
{
get
{
return _PropValue.Value;
}
}
}
}

View file

@ -0,0 +1,60 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
public class SessionCollection
{
IAudioSessionEnumerator _AudioSessionEnumerator;
internal SessionCollection(IAudioSessionEnumerator realEnumerator)
{
_AudioSessionEnumerator = realEnumerator;
}
public AudioSessionControl this[int index]
{
get
{
IAudioSessionControl2 _Result;
Marshal.ThrowExceptionForHR(_AudioSessionEnumerator.GetSession(index, out _Result));
return new AudioSessionControl(_Result);
}
}
public int Count
{
get
{
int result;
Marshal.ThrowExceptionForHR(_AudioSessionEnumerator.GetCount(out result));
return (int)result;
}
}
}
}

View file

@ -0,0 +1,70 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreAudioApi.Interfaces;
using System.Runtime.InteropServices;
namespace CoreAudioApi
{
public class SimpleAudioVolume
{
ISimpleAudioVolume _SimpleAudioVolume;
internal SimpleAudioVolume(ISimpleAudioVolume realSimpleVolume)
{
_SimpleAudioVolume = realSimpleVolume;
}
public float MasterVolume
{
get
{
float ret;
Marshal.ThrowExceptionForHR(_SimpleAudioVolume.GetMasterVolume(out ret));
return ret;
}
set
{
Guid Empty = Guid.Empty;
Marshal.ThrowExceptionForHR(_SimpleAudioVolume.SetMasterVolume(value, ref Empty));
}
}
public bool Mute
{
get
{
bool ret;
Marshal.ThrowExceptionForHR(_SimpleAudioVolume.GetMute(out ret));
return ret;
}
set
{
Guid Empty = Guid.Empty;
Marshal.ThrowExceptionForHR(_SimpleAudioVolume.SetMute(value, ref Empty));
}
}
}
}

View file

@ -0,0 +1,34 @@
/*
LICENSE
-------
Copyright (C) 2007-2010 Ray Molenkamp
This source code is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this source code or the software it produces.
Permission is granted to anyone to use this source code for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace CoreAudioApi.Interfaces
{
internal enum EStgmAccess
{
STGM_READ = 0x00000000,
STGM_WRITE = 0x00000001,
STGM_READWRITE = 0x00000002
}
}

View file

@ -0,0 +1,9 @@
<UserControl x:Class="AppleWirelessKeyboard.Glyphs.Eject"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Width="100" Height="100">
<Path Fill="White" Data="M 0,80 100,80 100,100 0,100 0,60 100,60 50,0 0,60 Z">
</Path>
</Grid>
</UserControl>

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Glyphs
{
/// <summary>
/// Interaction logic for Eject.xaml
/// </summary>
public partial class Eject : UserControl
{
public Eject()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,13 @@
<UserControl x:Class="AppleWirelessKeyboard.Glyphs.MuteOff"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas Width="163.855" Height="164.538" Margin="-1,0,0,-18">
<Path Fill="White" Data=" M 152.604,162.214 C 148.539,158.148 148.629,158.238 142.618,152.226 C 101.379,110.987 58.768,68.376 16.633,26.242 C 12.132,21.740 8.224,17.176 2.714,11.667 C -4.192,4.761 3.292,-5.161 11.636,3.183 C 19.854,11.402 19.325,10.936 26.632,18.243 C 69.051,60.662 110.754,102.365 152.616,144.227 C 154.698,146.309 157.776,149.448 160.886,152.558 C 168.823,160.495 159.042,168.651 152.604,162.214 Z"/>
<Path Fill="White" Data=" M 72.626,14.243 C 78.209,12.802 87.041,12.802 92.624,14.243 C 92.363,2.523 72.989,2.862 72.626,14.243 Z M 139.719,128.495 C 144.199,127.537 151.276,126.884 152.469,121.412 C 146.405,116.136 136.648,114.867 125.620,114.230 C 98.542,87.981 71.875,61.323 45.630,34.241 C 50.101,25.380 56.792,18.740 67.627,16.243 C 67.303,-1.437 96.603,-3.958 96.624,15.243 C 103.228,17.650 112.454,22.216 117.621,29.241 C 125.586,40.071 126.852,61.361 132.619,81.235 C 136.187,93.529 143.228,103.102 150.617,113.231 C 152.076,115.231 155.156,120.802 155.052,123.870 C 151.927,127.954 148.261,130.245 142.136,130.954 C 141.929,130.978 140.581,129.218 139.719,128.495 Z"/>
<Path Fill="White" Data=" M 38.631,51.238 C 58.212,70.652 81.374,91.817 97.623,111.231 C 66.567,111.837 33.375,110.308 12.634,121.230 C 16.553,128.329 26.643,128.957 35.631,130.229 C 53.513,132.760 77.622,134.195 99.623,133.228 C 105.669,132.962 113.560,131.825 118.303,131.579 C 120.291,131.475 121.100,132.975 122.620,134.228 C 86.909,139.281 15.636,136.245 9.201,123.668 C 13.580,110.886 22.064,104.682 27.632,93.233 C 33.447,81.277 35.330,67.870 38.631,51.238 Z"/>
<Path Fill="White" Data=" M 100.053,113.995 C 100.160,116.464 93.993,122.959 90.624,124.229 C 80.785,127.939 67.322,122.250 64.627,114.230 C 77.068,113.434 87.725,112.877 100.053,113.995 Z"/>
<Canvas.LayoutTransform>
<ScaleTransform ScaleX="0.7" ScaleY="0.7"/>
</Canvas.LayoutTransform>
</Canvas>
</UserControl>

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Glyphs
{
/// <summary>
/// Interaction logic for MuteOff.xaml
/// </summary>
public partial class MuteOff : UserControl
{
public MuteOff()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,11 @@
<UserControl x:Class="AppleWirelessKeyboard.Glyphs.MuteOn"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas Width="147.463" Height="135.280">
<Path Fill="White" Data=" M 54.993,110.208 C 35.873,111.317 16.495,111.064 4.000,119.207 C 7.177,126.871 18.307,126.976 26.997,128.206 C 55.356,132.220 93.980,132.028 120.985,128.206 C 130.092,126.917 139.963,126.250 143.982,119.207 C 122.687,108.571 86.501,108.381 54.993,110.208 Z M 63.992,12.220 C 69.575,10.779 78.406,10.779 83.989,12.220 C 83.729,0.500 64.355,0.839 63.992,12.220 Z M 147.463,122.667 C 138.546,134.917 101.529,134.546 73.991,135.205 C 60.249,135.534 45.733,134.763 32.996,133.205 C 20.070,131.625 6.654,130.173 0.000,122.207 C 2.986,111.388 10.176,108.109 15.998,98.209 C 33.394,68.630 24.135,21.592 58.993,14.220 C 59.375,-4.824 88.576,-4.656 88.989,14.220 C 120.463,20.713 115.664,59.859 125.984,86.211 C 131.115,99.312 146.046,113.417 147.463,122.667 Z"/>
<Path Fill="White" Data=" M 90.988,112.208 C 94.354,113.209 85.358,120.937 81.990,122.207 C 72.150,125.917 58.687,120.227 55.993,112.208 C 68.434,111.411 78.660,111.090 90.988,112.208 Z"/>
<Canvas.LayoutTransform>
<ScaleTransform ScaleX="0.7" ScaleY="0.7"/>
</Canvas.LayoutTransform>
</Canvas>
</UserControl>

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Glyphs
{
/// <summary>
/// Interaction logic for MuteOn.xaml
/// </summary>
public partial class MuteOn : UserControl
{
public MuteOn()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,8 @@
<UserControl x:Class="AppleWirelessKeyboard.Glyphs.Next"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas Width="120" Height="80">
<Path Fill="White" Data="F1 M 0,0 L 60,40 L 0,80 L 0,0 Z"/>
<Path Fill="White" Data="F1 M 60,0 L 120,40 L 60,80 L 60,0 Z"/>
</Canvas>
</UserControl>

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Glyphs
{
/// <summary>
/// Interaction logic for Next.xaml
/// </summary>
public partial class Next : UserControl
{
public Next()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,7 @@
<UserControl x:Class="AppleWirelessKeyboard.Glyphs.Off"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas Width="90.000" Height="90.000">
<Path Fill="White" Data=" M 45.000,6.000 C 23.461,6.000 6.000,23.461 6.000,45.000 C 6.000,66.539 23.461,84.000 45.000,84.000 C 66.539,84.000 84.000,66.539 84.000,45.000 C 84.000,23.461 66.539,6.000 45.000,6.000 Z M 90.000,45.000 C 90.000,69.853 69.853,90.000 45.000,90.000 C 20.147,90.000 0.000,69.853 0.000,45.000 C 0.000,20.147 20.147,0.000 45.000,0.000 C 69.853,0.000 90.000,20.147 90.000,45.000 Z"/>
</Canvas>
</UserControl>

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Glyphs
{
/// <summary>
/// Interaction logic for Off.xaml
/// </summary>
public partial class Off : UserControl
{
public Off()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,7 @@
<UserControl x:Class="AppleWirelessKeyboard.Glyphs.On"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas Width="6.000" Height="89.573">
<Path Fill="White" Data=" M 6.000,3.361 C 6.000,32.215 6.000,55.804 6.000,86.500 C 6.000,90.500 0.000,90.596 0.000,86.786 C 0.000,61.799 0.000,35.591 0.000,3.465 C 0.000,-1.284 6.000,-0.990 6.000,3.361 Z"/>
</Canvas>
</UserControl>

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Glyphs
{
/// <summary>
/// Interaction logic for On.xaml
/// </summary>
public partial class On : UserControl
{
public On()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,9 @@
<UserControl x:Class="AppleWirelessKeyboard.Glyphs.PlayPause"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas Width="120" Height="80">
<Path Fill="White" Data="F1 M 0,0 L 60,40 L 0,80 L 0,0 Z"/>
<Path Fill="White" Data="F1 M 120,80 L 100,80 L 100,0 L 120,0 L 120,80 Z"/>
<Path Fill="White" Data="F1 M 80,80 L 60,80 L 60,0 L 80,0 L 80,80 Z"/>
</Canvas>
</UserControl>

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Glyphs
{
/// <summary>
/// Interaction logic for Play.xaml
/// </summary>
public partial class PlayPause : UserControl
{
public PlayPause()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,8 @@
<UserControl x:Class="AppleWirelessKeyboard.Glyphs.Previous"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas Width="120" Height="80">
<Path Fill="White" Data="F1 M 120,80 L 60,40 L 120,0 L 120,80 Z"/>
<Path Fill="White" Data="F1 M 60,80 L 0,40 L 60,0 L 60,80 Z"/>
</Canvas>
</UserControl>

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Glyphs
{
/// <summary>
/// Interaction logic for Previous.xaml
/// </summary>
public partial class Previous : UserControl
{
public Previous()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,15 @@
<UserControl x:Class="AppleWirelessKeyboard.Glyphs.PrintScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas Width="179.578" Height="129.042">
<Path Fill="White" Data=" M 82.578,10.000 C 87.578,10.000 92.578,10.000 97.578,10.000 C 97.578,7.667 97.578,5.333 97.578,3.000 C 92.578,3.000 87.578,3.000 82.578,3.000 C 82.578,5.333 82.578,7.667 82.578,10.000 Z M 67.578,0.000 C 82.244,0.000 96.911,0.000 111.578,0.000 C 114.690,5.146 116.497,8.591 119.313,13.000 C 101.642,13.000 79.125,13.000 60.024,13.000"/>
<Path Fill="White" Data=" M 159.578,6.000 C 159.578,8.645 159.625,10.937 159.625,13.042 C 153.521,13.042 145.334,13.000 137.578,13.000 C 137.578,4.667 150.063,6.000 159.578,6.000 Z"/>
<Path Fill="White" Data=" M 24.578,8.000 C 29.244,8.000 33.911,8.000 38.578,8.000 C 38.578,9.667 38.578,11.333 38.578,13.000 C 33.578,13.000 29.578,13.000 24.578,13.000 C 24.578,10.188 24.578,10.420 24.578,8.000 Z"/>
<Path Fill="White" Data=" M 179.578,51.000 C 166.578,51.000 153.188,51.000 140.188,51.000 C 136.021,46.417 132.169,40.707 125.578,37.000 C 105.396,25.649 80.640,36.038 71.578,51.000 C 47.911,51.000 23.730,51.000 0.063,51.000 C 0.063,41.089 -0.029,32.500 0.009,25.125 C 0.053,16.688 6.833,14.797 10.188,14.797 C 22.563,14.797 39.860,15.000 54.578,15.000 C 79.632,15.000 138.398,14.797 166.500,14.797 C 176.083,14.797 179.578,16.750 179.578,25.500 C 179.578,32.917 179.578,40.833 179.578,51.000 Z"/>
<Path Fill="White" Data=" M 101.578,47.000 C 119.659,43.946 136.605,60.650 129.578,81.000 C 123.352,99.030 97.963,98.708 88.578,90.000 C 74.763,77.183 79.773,50.683 101.578,47.000 Z"/>
<Path Fill="White" Data=" M 19.563,129.042 C 0.009,129.042 0.063,118.625 0.063,104.000 C 0.063,95.058 0.063,108.333 0.063,91.125 C 0.063,78.456 0.063,64.917 0.063,55.000 C 22.729,55.000 47.438,55.000 70.104,55.000 C 67.730,60.833 66.311,65.675 66.578,73.000 C 68.225,118.225 133.223,120.977 143.578,83.000 C 145.548,75.774 145.763,63.452 141.578,55.000 C 152.438,55.000 166.938,55.000 179.396,55.000 C 179.396,66.954 179.578,76.806 179.578,90.000 C 179.578,100.926 179.578,102.828 179.578,110.250 C 179.578,120.957 177.349,128.750 159.500,128.750"/>
<Canvas.LayoutTransform>
<ScaleTransform ScaleX="0.65" ScaleY="0.65"/>
</Canvas.LayoutTransform>
</Canvas>
</UserControl>

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Glyphs
{
/// <summary>
/// Interaction logic for PrintScreen.xaml
/// </summary>
public partial class PrintScreen : UserControl
{
public PrintScreen()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,10 @@
<UserControl x:Class="AppleWirelessKeyboard.Glyphs.TaskManager"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas Width="192.616" Height="229.000">
<Path Fill="White" Data=" M 70.347,0.000 C 82.460,47.220 92.673,96.341 104.347,144.000 C 114.069,120.722 121.118,94.771 130.347,71.000 C 139.953,90.727 147.412,112.602 156.347,133.000 C 176.366,133.000 192.616,131.063 192.616,143.438 C 192.616,160.000 156.491,156.000 140.347,156.000 C 138.030,149.316 134.747,143.600 133.347,136.000 C 120.378,165.031 112.071,198.725 100.347,229.000 C 89.396,186.952 80.544,142.803 70.347,100.000 C 65.305,117.958 60.846,136.499 57.347,156.000 C 38.741,156.000 0.000,159.500 0.000,145.582 C 0.000,131.333 18.470,133.000 37.347,133.000 C 49.720,90.039 58.673,43.660 70.347,0.000 Z"/>
<Canvas.LayoutTransform>
<ScaleTransform ScaleX="0.5" ScaleY="0.5"/>
</Canvas.LayoutTransform>
</Canvas>
</UserControl>

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Glyphs
{
/// <summary>
/// Interaction logic for TaskManager.xaml
/// </summary>
public partial class TaskManager : UserControl
{
public TaskManager()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,14 @@
<UserControl x:Class="AppleWirelessKeyboard.Glyphs.VolumeOff"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="192" d:DesignWidth="192">
<Canvas Width="49.5" Height="84">
<Path Fill="White" Data=" M 27.000,76.000 C 27.000,76.000 9.000,76.000 0.000,76.000 C 0.000,63.333 0.000,38.000 0.000,38.000 L 26.000,38.000 L 65.000,0.000 L 66.000,112.000"/>
<Canvas.RenderTransform>
<ScaleTransform ScaleX="0.75" ScaleY="0.75"/>
</Canvas.RenderTransform>
</Canvas>
</UserControl>

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Glyphs
{
/// <summary>
/// Interaction logic for VolumeOff.xaml
/// </summary>
public partial class VolumeOff : UserControl
{
public VolumeOff()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,17 @@
<UserControl x:Class="AppleWirelessKeyboard.Glyphs.VolumeOn"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="192" d:DesignWidth="192">
<Canvas Width="119.46525" Height="109.50375">
<Path Fill="White" Data=" M 114.000,2.008 C 120.750,-8.742 159.287,24.846 159.287,74.605 C 159.287,115.342 121.000,155.508 111.000,144.008 C 104.500,134.175 146.375,121.403 146.375,74.605 C 146.375,22.008 105.500,16.258 114.000,2.008 Z"/>
<Path Fill="White" Data=" M 27.000,94.008 C 27.000,94.008 9.000,94.008 0.000,94.008 C 0.000,81.341 0.000,56.008 0.000,56.008 L 26.000,56.008 L 65.000,18.008 L 66.000,130.008"/>
<Path Fill="White" Data=" M 96.000,123.008 C 90.125,113.758 117.000,106.327 117.000,76.883 C 117.000,41.258 91.750,33.633 99.463,26.237 C 108.294,17.768 126.785,49.633 126.750,76.508 C 126.715,103.032 101.375,130.883 96.000,123.008 Z"/>
<Path Fill="White" Data=" M 84.499,98.220 C 82.567,93.070 94.460,87.513 94.460,73.824 C 94.460,62.008 78.208,57.856 83.651,51.260 C 87.917,46.092 102.259,59.757 102.281,73.824 C 102.305,88.341 87.431,106.035 84.499,98.220 Z"/>
<Canvas.RenderTransform>
<ScaleTransform ScaleX="0.75" ScaleY="0.75"/>
</Canvas.RenderTransform>
</Canvas>
</UserControl>

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Glyphs
{
/// <summary>
/// Interaction logic for VolumeOn.xaml
/// </summary>
public partial class VolumeOn : UserControl
{
public VolumeOn()
{
InitializeComponent();
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View file

@ -0,0 +1,192 @@
using System;
using System.Runtime.InteropServices;
using System.IO;
using Microsoft.Win32.SafeHandles;
namespace AppleWirelessKeyboard
{
/// <summary>
/// Win32 import information for use with the Wiimote library
/// </summary>
class HIDImports
{
//
// Flags controlling what is included in the device information set built
// by SetupDiGetClassDevs
//
public const int DIGCF_DEFAULT = 0x00000001; // only valid with DIGCF_DEVICEINTERFACE
public const int DIGCF_PRESENT = 0x00000002;
public const int DIGCF_ALLCLASSES = 0x00000004;
public const int DIGCF_PROFILE = 0x00000008;
public const int DIGCF_DEVICEINTERFACE = 0x00000010;
[Flags]
public enum EFileAttributes : uint
{
Readonly = 0x00000001,
Hidden = 0x00000002,
System = 0x00000004,
Directory = 0x00000010,
Archive = 0x00000020,
Device = 0x00000040,
Normal = 0x00000080,
Temporary = 0x00000100,
SparseFile = 0x00000200,
ReparsePoint = 0x00000400,
Compressed = 0x00000800,
Offline = 0x00001000,
NotContentIndexed = 0x00002000,
Encrypted = 0x00004000,
Write_Through = 0x80000000,
Overlapped = 0x40000000,
NoBuffering = 0x20000000,
RandomAccess = 0x10000000,
SequentialScan = 0x08000000,
DeleteOnClose = 0x04000000,
BackupSemantics = 0x02000000,
PosixSemantics = 0x01000000,
OpenReparsePoint = 0x00200000,
OpenNoRecall = 0x00100000,
FirstPipeInstance = 0x00080000
}
[StructLayout(LayoutKind.Sequential)]
public struct SP_DEVINFO_DATA
{
public uint cbSize;
public Guid ClassGuid;
public uint DevInst;
public IntPtr Reserved;
}
[StructLayout(LayoutKind.Sequential)]
public struct SP_DEVICE_INTERFACE_DATA
{
public int cbSize;
public Guid InterfaceClassGuid;
public int Flags;
public IntPtr RESERVED;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SP_DEVICE_INTERFACE_DETAIL_DATA
{
public UInt32 cbSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string DevicePath;
}
[StructLayout(LayoutKind.Sequential)]
public struct HIDD_ATTRIBUTES
{
public int Size;
public short VendorID;
public short ProductID;
public short VersionNumber;
}
[DllImport(@"hid.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern void HidD_GetHidGuid(out Guid gHid);
[DllImport("hid.dll")]
public static extern Boolean HidD_GetAttributes(IntPtr HidDeviceObject, ref HIDD_ATTRIBUTES Attributes);
[DllImport("hid.dll")]
internal extern static bool HidD_SetOutputReport(
IntPtr HidDeviceObject,
byte[] lpReportBuffer,
uint ReportBufferLength);
[DllImport(@"setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr SetupDiGetClassDevs(
ref Guid ClassGuid,
[MarshalAs(UnmanagedType.LPTStr)] string Enumerator,
IntPtr hwndParent,
UInt32 Flags
);
[DllImport(@"setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern Boolean SetupDiEnumDeviceInterfaces(
IntPtr hDevInfo,
//ref SP_DEVINFO_DATA devInfo,
IntPtr devInvo,
ref Guid interfaceClassGuid,
Int32 memberIndex,
ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData
);
[DllImport(@"setupapi.dll", SetLastError = true)]
public static extern Boolean SetupDiGetDeviceInterfaceDetail(
IntPtr hDevInfo,
ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData,
IntPtr deviceInterfaceDetailData,
UInt32 deviceInterfaceDetailDataSize,
out UInt32 requiredSize,
IntPtr deviceInfoData
);
[DllImport(@"setupapi.dll", SetLastError = true)]
public static extern Boolean SetupDiGetDeviceInterfaceDetail(
IntPtr hDevInfo,
ref SP_DEVICE_INTERFACE_DATA deviceInterfaceData,
ref SP_DEVICE_INTERFACE_DETAIL_DATA deviceInterfaceDetailData,
UInt32 deviceInterfaceDetailDataSize,
out UInt32 requiredSize,
IntPtr deviceInfoData
);
[DllImport(@"setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern UInt16 SetupDiDestroyDeviceInfoList(IntPtr hDevInfo);
[DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern SafeFileHandle CreateFile(
string fileName,
[MarshalAs(UnmanagedType.U4)] FileAccess fileAccess,
[MarshalAs(UnmanagedType.U4)] FileShare fileShare,
IntPtr securityAttributes,
[MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
[MarshalAs(UnmanagedType.U4)] EFileAttributes flags,
IntPtr template);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CloseHandle(IntPtr hObject);
[DllImport("setupapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetupDiGetDeviceRegistryProperty(
IntPtr DeviceInfoSet,
ref SP_DEVINFO_DATA DeviceInfoData,
uint Property,
out UInt32 PropertyRegDataType,
IntPtr PropertyBuffer,
uint PropertyBufferSize,
out UInt32 RequiredSize);
public enum SPDRP
{
SPDRP_DEVICEDESC = 0x00000000,
SPDRP_HARDWAREID = 0x00000001,
SPDRP_COMPATIBLEIDS = 0x00000002,
SPDRP_NTDEVICEPATHS = 0x00000003,
SPDRP_SERVICE = 0x00000004,
SPDRP_CONFIGURATION = 0x00000005,
SPDRP_CONFIGURATIONVECTOR = 0x00000006,
SPDRP_CLASS = 0x00000007,
SPDRP_CLASSGUID = 0x00000008,
SPDRP_DRIVER = 0x00000009,
SPDRP_CONFIGFLAGS = 0x0000000A,
SPDRP_MFG = 0x0000000B,
SPDRP_FRIENDLYNAME = 0x0000000C,
SPDRP_LOCATION_INFORMATION = 0x0000000D,
SPDRP_PHYSICAL_DEVICE_OBJECT_NAME = 0x0000000E,
SPDRP_CAPABILITIES = 0x0000000F,
SPDRP_UI_NUMBER = 0x00000010,
SPDRP_UPPERFILTERS = 0x00000011,
SPDRP_LOWERFILTERS = 0x00000012,
SPDRP_MAXIMUM_PROPERTY = 0x00000013,
}
[DllImport("setupapi.dll", SetLastError = true)]
public static extern bool SetupDiEnumDeviceInfo(IntPtr DeviceInfoSet, uint MemberIndex, ref SP_DEVINFO_DATA DeviceInfoData);
}
}

View file

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Threading.Tasks;
namespace AppleWirelessKeyboard
{
public static class IoControl
{
#region DeviceIoControl
const int OPEN_EXISTING = 3;
const uint GENERIC_READ = 0x80000000;
const uint GENERIC_WRITE = 0x40000000;
const uint FILE_SHARE_WRITE = 0x00000002;
const uint IOCTL_STORAGE_EJECT_MEDIA = 2967560;
[DllImport("kernel32")]
private static extern IntPtr CreateFile
(string filename, uint desiredAccess,
uint shareMode, IntPtr securityAttributes,
int creationDisposition, int flagsAndAttributes,
IntPtr templateFile);
[DllImport("kernel32")]
private static extern int DeviceIoControl
(IntPtr deviceHandle, uint ioControlCode,
IntPtr inBuffer, int inBufferSize,
IntPtr outBuffer, int outBufferSize,
ref int bytesReturned, IntPtr overlapped);
[DllImport("kernel32")]
private static extern int CloseHandle(IntPtr handle);
#endregion
public static void EjectMedia(char driveLetter)
{
try
{
string path = "\\\\.\\" + driveLetter + ":";
IntPtr handle = CreateFile(path, GENERIC_READ, FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
if ((long)handle == -1)
{
throw new IOException("Unable to open drive " + driveLetter);
}
int dummy = 0;
DeviceIoControl(handle, IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero, 0, IntPtr.Zero, 0, ref dummy, IntPtr.Zero);
CloseHandle(handle);
}
catch { }
}
public static void EjectAllMedia()
{
Task.Factory.StartNew(() =>
{
NotificationCenter.NotifyEject();
foreach (DriveInfo drive in DriveInfo.GetDrives())
if (drive.DriveType == DriveType.CDRom)
{
EjectMedia(drive.Name[0]);
}
});
}
}
}

View file

@ -0,0 +1,172 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Input;
using System.Threading;
using System.Threading.Tasks;
namespace AppleWirelessKeyboard
{
public static class KeyboardControl
{
const int VK_SNAPSHOT = 44;
const int VK_DELETE = 46;
const int VK_MEDIA_NEXT_TRACK = 176;
const int VK_MEDIA_PREV_TRACK = 177;
const int VK_MEDIA_STOP = 178;
const int VK_MEDIA_PLAY_PAUSE = 179;
const int VK_END = 37;
const int VK_HOME = 36;
const int VK_PAGEUP = 33;
const int VK_PAGEDOWN = 35;
const int VK_F3 = 117;
const int VK_INSERT = 45;
public static void Send(int VKey, KeyboardEvent e = KeyboardEvent.Both)
{
switch (e)
{
case KeyboardEvent.Both:
{
keybd_event((byte)VKey, 0, 0, 0);
keybd_event((byte)VKey, 0, 2, 0);
}
break;
case KeyboardEvent.Down:
keybd_event((byte)VKey, 0, 0, 0);
break;
case KeyboardEvent.Up:
keybd_event((byte)VKey, 0, 2, 0);
break;
}
}
public static void SendInsert()
{
Task.Factory.StartNew(() =>
{
Send(VK_INSERT);
});
}
public static void SendDelete()
{
Task.Factory.StartNew(() =>
{
Send(VK_DELETE);
});
}
public static void SendPrintScreen()
{
Task.Factory.StartNew(() =>
{
Send(VK_SNAPSHOT);
Thread.Sleep(100);
NotificationCenter.NotifyPrintScreen();
});
}
public static void SendPlayPause()
{
Task.Factory.StartNew(() =>
{
if (iTunesControl.iTunesRunning)
iTunesControl.PlayPause();
else
Send(VK_MEDIA_PLAY_PAUSE);
NotificationCenter.NotifyPlayPause();
});
}
public static void SendNextTrack()
{
Task.Factory.StartNew(() =>
{
if (iTunesControl.iTunesRunning)
iTunesControl.NextSong();
else
Send(VK_MEDIA_NEXT_TRACK);
NotificationCenter.NotifyNext();
});
}
public static void SendPreviousTrack()
{
Task.Factory.StartNew(() =>
{
if (iTunesControl.iTunesRunning)
iTunesControl.PreviousSong();
else
Send(VK_MEDIA_PREV_TRACK);
NotificationCenter.NotifyPrevious();
});
}
public static void OpenTaskManager()
{
Task.Factory.StartNew(() =>
{
Process taskmgr = Process.GetProcessesByName("taskmgr.exe").FirstOrDefault();
if (taskmgr != null)
SetForegroundWindow(taskmgr.MainWindowHandle);
else
Process.Start("taskmgr.exe");
NotificationCenter.NotifyTaskManager();
});
}
#region PInvoke
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
public enum KeyboardEvent
{
Down = 0, Up = 2, Both
}
#endregion
public static void SendPageUp()
{
Task.Factory.StartNew(() =>
{
Send(VK_PAGEUP);
});
}
public static void SendPageDown()
{
Task.Factory.StartNew(() =>
{
Send(VK_PAGEDOWN);
});
}
public static void SendHome()
{
Task.Factory.StartNew(() =>
{
Send(VK_HOME);
});
}
public static void SendEnd()
{
Task.Factory.StartNew(() =>
{
Send(VK_END);
});
}
public static void SendF3()
{
Task.Factory.StartNew(() =>
{
Send(VK_F3);
});
}
}
}

View file

@ -0,0 +1,168 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Threading.Tasks;
using System.Threading;
using System.Windows;
namespace AppleWirelessKeyboard
{
public static class KeyboardHandler
{
static KeyboardHandler()
{
PowerButtonPressCount = 0;
}
public static bool FMode
{
get
{
return AppleWirelessKeyboard.Properties.Settings.Default.FMode;
}
set
{
if (AppleWirelessKeyboard.Properties.Settings.Default.FMode != value)
{
AppleWirelessKeyboard.Properties.Settings.Default.FMode = value;
if (value)
NotificationCenter.NotifyOn();
else NotificationCenter.NotifyOff();
}
}
}
public static void HandleEject()
{
if (!AppleKeyboardHID2.FnDown)
FMode = !FMode;
else IoControl.EjectAllMedia();
}
public static bool HandleKeyDown(KeyboardListener.KeyHookEventArgs e)
{
bool F = (FMode || e.ModifierFn) && !e.ModifierAnyNative;
switch (e.Key)
{
case Key.F3:
if (F)
{
KeyboardControl.SendPrintScreen();
return true;
}
break;
case Key.F4:
if (F)
{
KeyboardControl.OpenTaskManager();
return true;
}
break;
case Key.F2:
if (F)
{
KeyboardControl.SendF3();
return true;
}
break;
case Key.F7:
if (F)
{
KeyboardControl.SendPreviousTrack();
return true;
}
break;
case Key.F8:
if (F)
{
KeyboardControl.SendPlayPause();
return true;
}
break;
case Key.F9:
if (F)
{
KeyboardControl.SendNextTrack();
return true;
}
break;
case Key.F10:
if (F)
{
VolumeControl.ToggleMute();
return true;
}
break;
case Key.F11:
if (F)
{
VolumeControl.VolumeDown();
return true;
}
break;
case Key.F12:
if (F)
{
VolumeControl.VolumeUp();
return true;
}
break;
case Key.Back:
if (e.ModifierFn)
{
KeyboardControl.SendDelete();
return true;
}
break;
case Key.Up:
if (e.ModifierFn)
{
KeyboardControl.SendPageUp();
return true;
}
break;
case Key.Down:
if (e.ModifierFn)
{
KeyboardControl.SendPageDown();
return true;
}
break;
case Key.Left:
if(e.ModifierFn)
{
KeyboardControl.SendHome();
return true;
}
break;
case Key.Right:
if (e.ModifierFn)
{
KeyboardControl.SendEnd();
return true;
}
break;
case Key.Enter:
if (e.ModifierFn)
{
KeyboardControl.SendInsert();
return true;
}
break;
}
if (e.ModifierAnyAlt && (FMode || e.ModifierFn))
if (e.Key == Key.F3)
{
KeyboardControl.SendPrintScreen();
return true;
}
return false;
}
public static int PowerButtonPressCount { get; set; }
}
}

View file

@ -0,0 +1,210 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Input;
using System.Diagnostics;
using System.Windows;
namespace AppleWirelessKeyboard
{
/// <summary>
/// A class that manages a global low level keyboard hook
/// </summary>
public static class KeyboardListener
{
static KeyboardListener()
{
HookedKeys = new List<Key>();
Hook = IntPtr.Zero;
}
#region PInvoke Structures
public delegate int keyboardHookProc(int code, int wParam, ref keyboardHookStruct lParam);
public struct keyboardHookStruct
{
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
}
private const int WH_KEYBOARD_LL = 13;
private const int WM_KEYDOWN = 0x100;
private const int WM_KEYUP = 0x101;
private const int WM_SYSKEYDOWN = 0x104;
private const int WM_SYSKEYUP = 0x105;
#endregion
#region Public declarations
public static List<Key> HookedKeys { get; set; }
internal static IntPtr Hook { get; set; }
public static event KeyHookEventHandler KeyDown;
public static event KeyHookEventHandler KeyUp;
public static bool ModifierLeftAlt { get; set; }
public static bool ModifierRightAlt { get; set; }
public static bool ModifierLeftCtrl { get; set; }
public static bool ModifierRightCtrl { get; set; }
public static bool ModifierLeftShift { get; set; }
public static bool ModifierRightShift { get; set; }
public static bool ModifierLeftWin { get; set; }
public static bool ModifierRightWin { get; set; }
public static bool ModifierCapsLock { get; set; }
public static bool ModifierFn { get; set; }
public class KeyHookEventArgs
{
public KeyHookEventArgs()
{
}
public Key Key { get; set; }
public bool ModifierLeftAlt { get; set; }
public bool ModifierRightAlt { get; set; }
public bool ModifierLeftCtrl { get; set; }
public bool ModifierRightCtrl { get; set; }
public bool ModifierLeftShift { get; set; }
public bool ModifierRightShift { get; set; }
public bool ModifierLeftWin { get; set; }
public bool ModifierRightWin { get; set; }
public bool ModifierCapsLock { get; set; }
public bool ModifierFn { get; set; }
public bool ModifierAnyAlt { get { return ModifierLeftAlt || ModifierRightAlt; } set { ModifierLeftAlt = value; } }
public bool ModifierAnyCtrl { get { return ModifierLeftCtrl || ModifierRightCtrl; } set { ModifierLeftCtrl = value; } }
public bool ModifierAnyShift { get { return ModifierLeftShift || ModifierRightShift; } set { ModifierLeftShift = value; } }
public bool ModifierAnyWin { get { return ModifierLeftWin || ModifierRightWin; } set { ModifierLeftWin = value; } }
public bool ModifierAnyNative { get { return (((ModifierAnyAlt) || (ModifierAnyWin)) || ((ModifierAnyCtrl) || (ModifierAnyShift))); } }
public bool ModifierAny { get { return ((ModifierAny) || (ModifierFn)); } }
}
public delegate bool KeyHookEventHandler(KeyHookEventArgs e);
#endregion
#region Public Methods
internal static void SetModifiers(Key key, bool IsPressed, int VKey)
{
switch (key)
{
case Key.LeftAlt:
ModifierLeftAlt = IsPressed;
break;
case Key.RightAlt:
ModifierRightAlt = IsPressed;
break;
case Key.RightCtrl:
ModifierRightCtrl = IsPressed;
break;
case Key.LeftCtrl:
ModifierLeftCtrl = IsPressed;
break;
case Key.LeftShift:
ModifierLeftShift = IsPressed;
break;
case Key.RightShift:
ModifierRightShift = IsPressed;
break;
case Key.CapsLock:
ModifierCapsLock = IsPressed;
break;
case Key.LWin:
ModifierLeftWin = IsPressed;
break;
case Key.RWin:
ModifierRightWin = IsPressed;
break;
}
if (!AppleKeyboardHID2.Registered)
AppleKeyboardHID2.Start();
}
internal static KeyHookEventArgs CreateEventArgs(Key key)
{
return new KeyHookEventArgs()
{
Key = key,
ModifierCapsLock = ModifierCapsLock,
ModifierLeftAlt = ModifierLeftAlt,
ModifierRightAlt = ModifierRightAlt,
ModifierLeftCtrl = ModifierLeftCtrl,
ModifierRightCtrl = ModifierRightCtrl,
ModifierLeftShift = ModifierLeftShift,
ModifierRightShift = ModifierRightShift,
ModifierLeftWin = ModifierLeftWin,
ModifierRightWin = ModifierRightWin,
ModifierFn = ModifierFn
};
}
public static keyboardHookProc HookProcessor { get; set; }
public static void Register()
{
HookProcessor = Hook_Callback;
IntPtr hInstance = GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName);
Hook = SetWindowsHookEx(WH_KEYBOARD_LL, HookProcessor, hInstance, 0);
}
public static void UnRegister()
{
UnhookWindowsHookEx(Hook);
}
public static bool TriggerKeyDown(KeyHookEventArgs args)
{
if (KeyDown != null)
return KeyDown(args);
else return false;
}
public static bool TriggerKeyUp(KeyHookEventArgs args)
{
if (KeyUp != null)
return KeyUp(args);
else return false;
}
public static int Hook_Callback(int code, int wParam, ref keyboardHookStruct lParam)
{
if (code >= 0)
{
Key key = (Key)System.Windows.Input.KeyInterop.KeyFromVirtualKey(lParam.vkCode);
bool IsPressed = (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN);
SetModifiers(key, IsPressed, lParam.vkCode);
if (HookedKeys.Contains(key))
{
KeyHookEventArgs kea = CreateEventArgs(key);
bool Handled = false;
if (IsPressed)
Handled = TriggerKeyDown(kea);
else
Handled = TriggerKeyUp(kea);
if (Handled)
return 1;
}
}
return CallNextHookEx(Hook, code, wParam, ref lParam);
}
#endregion
#region DLL imports
[DllImport("user32.dll")]
static extern IntPtr SetWindowsHookEx(int idHook, keyboardHookProc callback, IntPtr hInstance, uint threadId);
[DllImport("user32.dll")]
static extern bool UnhookWindowsHookEx(IntPtr hInstance);
[DllImport("user32.dll")]
static extern int CallNextHookEx(IntPtr idHook, int nCode, int wParam, ref keyboardHookStruct lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr GetModuleHandle(string lpModuleName);
#endregion
}
}

View file

@ -0,0 +1,15 @@
<Window x:Class="AppleWirelessKeyboard.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ShowInTaskbar="False" Background="Transparent" Topmost="True"
WindowStyle="None" WindowStartupLocation="CenterScreen" Height="192" Width="192" AllowsTransparency="True">
<Border Background="#99000000" CornerRadius="12">
<Grid>
<ContentControl Content="{Binding Glyph}"/>
<StackPanel Height="6" Width="141" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="12" Orientation="Horizontal" Name="ValueBar"/>
<Grid.Effect>
<DropShadowEffect ShadowDepth="2" Opacity="0.9"/>
</Grid.Effect>
</Grid>
</Border>
</Window>

View file

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
namespace AppleWirelessKeyboard
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public void ShowOff(Control glyph, bool valueBar = false, int value = 0)
{
this.DataContext = new { Glyph = glyph };
if (valueBar) ValueBar.Visibility = System.Windows.Visibility.Visible;
else ValueBar.Visibility = System.Windows.Visibility.Collapsed;
MakeValue(value);
this.Show();
DoubleAnimationUsingKeyFrames Fade = new DoubleAnimationUsingKeyFrames();
Fade.Duration = new Duration(TimeSpan.FromSeconds(1));
Fade.KeyFrames.Add(new LinearDoubleKeyFrame(1, KeyTime.FromPercent(0)));
Fade.KeyFrames.Add(new LinearDoubleKeyFrame(1, KeyTime.FromPercent(0.5)));
Fade.KeyFrames.Add(new LinearDoubleKeyFrame(0, KeyTime.FromPercent(1)));
BeginAnimation(OpacityProperty, Fade);
}
public void MakeValue(int value)
{
ValueBar.Children.Clear();
for (int i = 0; i <= value; i++)
{
Rectangle rect = new Rectangle();
rect.Fill = new SolidColorBrush(Colors.White);
rect.Width = 6;
rect.Height = 6;
rect.Margin = new Thickness(0, 0, 3, 0);
ValueBar.Children.Add(rect);
}
}
}
}

View file

@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AppleWirelessKeyboard
{
public static class NotificationCenter
{
static NotificationCenter()
{
}
public static void NotifyMuteOn()
{
App.Window.Dispatcher.Invoke(new Action(delegate
{
App.Window.ShowOff(new Glyphs.MuteOn());
}));
}
public static void NotifyMuteOff()
{
App.Window.Dispatcher.Invoke(new Action(delegate
{
App.Window.ShowOff(new Glyphs.MuteOff());
}));
}
public static void NotifyNoVolume()
{
App.Window.Dispatcher.Invoke(new Action(delegate
{
App.Window.ShowOff(new Glyphs.VolumeOff());
}));
}
public static void NotifyVolumeLevel(int level)//1-16
{
App.Window.Dispatcher.Invoke(new Action(delegate
{
App.Window.ShowOff(new Glyphs.VolumeOn(), true, level);
}));
}
public static void NotifyTaskManager()
{
App.Window.Dispatcher.Invoke((Action)delegate
{
App.Window.ShowOff(new Glyphs.TaskManager());
});
}
public static void NotifyPrintScreen()
{
App.Window.Dispatcher.Invoke((Action)delegate
{
App.Window.ShowOff(new Glyphs.PrintScreen());
});
}
public static void NotifyOn()
{
App.Window.Dispatcher.Invoke((Action)delegate
{
App.Window.ShowOff(new Glyphs.On());
});
}
public static void NotifyOff()
{
App.Window.Dispatcher.Invoke((Action)delegate
{
App.Window.ShowOff(new Glyphs.Off());
});
}
public static void NotifyPlayPause()
{
App.Window.Dispatcher.Invoke((Action)delegate
{
App.Window.ShowOff(new Glyphs.PlayPause());
});
}
public static void NotifyPrevious()
{
App.Window.Dispatcher.Invoke((Action)delegate
{
App.Window.ShowOff(new Glyphs.Previous());
});
}
public static void NotifyNext()
{
App.Window.Dispatcher.Invoke((Action)delegate
{
App.Window.ShowOff(new Glyphs.Next());
});
}
internal static void NotifyEject()
{
App.Window.Dispatcher.Invoke((Action)delegate
{
App.Window.ShowOff(new Glyphs.Eject());
});
}
}
}

View file

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Threading;
using System.Windows;
namespace AppleWirelessKeyboard
{
public class PowerControl
{
public static void Hibernate()
{
Task.Factory.StartNew(() =>
{
if (PowerStatusBox.PowerAction("Hibernate", 10))
SetSuspendState(true, true, true);
});
}
public static void Shutdown()
{
Task.Factory.StartNew(() =>
{
if (PowerStatusBox.PowerAction("Shut Down", 10))
{
ProcessStartInfo si = new ProcessStartInfo("shutdown", "/s /t 0");
si.CreateNoWindow = true;
si.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(si);
}
});
}
[DllImport("powrprof.dll", SetLastError = true)]
static extern bool SetSuspendState(bool hibernate, bool forceCritical, bool disableWakeEvent);
}
}

View file

@ -0,0 +1,16 @@
<Window x:Class="AppleWirelessKeyboard.PowerStatusBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="Transparent" WindowStartupLocation="CenterScreen"
Height="200" Width="320" WindowStyle="None" Closing="Window_Closing" Topmost="True" AllowsTransparency="True" ShowInTaskbar="False" Loaded="Window_Loaded">
<Border CornerRadius="10" Background="#99000000">
<Grid>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Name="txtStatus" Foreground="White" Text="The system is about to shut down in 10 seconds.">
<TextBlock.BitmapEffect>
<DropShadowBitmapEffect ShadowDepth="2" Opacity="0.9"/>
</TextBlock.BitmapEffect>
</TextBlock>
<Button VerticalAlignment="Bottom" HorizontalAlignment="Left" Name="btnCancel" Content="Cancel" Width="64" Margin="20" Click="btnCancel_Click"/>
<Button VerticalAlignment="Bottom" HorizontalAlignment="Right" Name="btnOK" Content="OK" Width="64" Margin="20" Click="btnOK_Click"/>
</Grid>
</Border>
</Window>

View file

@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Timers;
using System.Windows.Threading;
namespace AppleWirelessKeyboard
{
/// <summary>
/// Interaction logic for PowerStatusBox.xaml
/// </summary>
public partial class PowerStatusBox : Window
{
public PowerStatusBox()
{
InitializeComponent();
T = new Timer(1000);
T.Elapsed += new ElapsedEventHandler(T_Elapsed);
}
void T_Elapsed(object sender, ElapsedEventArgs e)
{
if (Seconds > 0)
{
Seconds--;
Status();
}
else
{
T.Stop();
Dispatcher.Invoke((Action)delegate
{
DialogResult = true;
Close();
});
}
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
T.Stop();
DialogResult = false;
}
private void btnOK_Click(object sender, RoutedEventArgs e)
{
T.Stop();
DialogResult = true;
}
public void Status()
{
Dispatcher.Invoke((Action)delegate
{
txtStatus.Text = string.Format("The system is about to {0} in {1} seconds.", Action, Seconds);
});
}
public string Action { get; set; }
public int Seconds { get; set; }
public Timer T { get; set; }
public static bool PowerAction(string action, int seconds)
{
bool ret = false;
App.Current.Dispatcher.Invoke((Action)delegate
{
PowerStatusBox frm = new PowerStatusBox();
frm.Action = action;
frm.Seconds = seconds;
frm.Status();
ret = (bool)frm.ShowDialog();
});
return ret;
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!DialogResult.HasValue)
{
T.Stop();
DialogResult = false;
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Status();
T.Start();
}
}
}

View file

@ -0,0 +1,55 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AppleWirelessKeyboard")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("uxsoft")]
[assembly: AssemblyProduct("AppleWirelessKeyboard")]
[assembly: AssemblyCopyright("Copyright © uxsoft 2010-2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]

View file

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.225
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AppleWirelessKeyboard.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AppleWirelessKeyboard.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View file

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -0,0 +1,86 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.225
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AppleWirelessKeyboard.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool FMode {
get {
return ((bool)(this["FMode"]));
}
set {
this["FMode"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool FnEnabled {
get {
return ((bool)(this["FnEnabled"]));
}
set {
this["FnEnabled"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string Version {
get {
return ((string)(this["Version"]));
}
set {
this["Version"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool SwapCtrlFn {
get {
return ((bool)(this["SwapCtrlFn"]));
}
set {
this["SwapCtrlFn"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string Hash {
get {
return ((string)(this["Hash"]));
}
set {
this["Hash"] = value;
}
}
}
}

View file

@ -0,0 +1,21 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="AppleWirelessKeyboard.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="FMode" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="FnEnabled" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="Version" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="SwapCtrlFn" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="Hash" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

View file

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
namespace AppleWirelessKeyboard
{
public static class StartupShortcut
{
public static void Register()
{
//string file = GetShortcutPath();
//string shortcut = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri.ToString();
//StreamWriter sw = new StreamWriter(file);
//sw.Write(shortcut);
//sw.Close();
}
public static void UnRegister()
{
File.Delete(GetShortcutPath());
}
public static string GetShortcutPath()
{
string folder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
return Path.Combine(folder, Path.ChangeExtension(Assembly.GetEntryAssembly().GetName().Name, ".appref-ms"));
}
public static bool IsRegistered
{
get
{
return File.Exists(GetShortcutPath());
}
}
}
}

View file

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using AppleWirelessKeyboard.Views;
namespace AppleWirelessKeyboard
{
public static class TrayIcon
{
static TrayIcon()
{
NotifyIcon icon = new NotifyIcon();
icon.Text = "AppleWirelessKeyboard";
icon.Icon = new Icon(App.GetResourceStream(new Uri("pack://application:,,,/Gnome-Preferences-Desktop-Keyboard-Shortcuts.ico")).Stream);
icon.Visible = true;
MenuItem[] menuItems = new[] {
new MenuItem("Configure", TriggerConfigure),
new MenuItem("Restart", TriggerRestart),
new MenuItem("Refresh", TriggerRefresh),
new MenuItem("Exit", TriggerExit)
};
ContextMenu menu = new ContextMenu(menuItems);
icon.ContextMenu = menu;
}
public static void Show() { }
private static void TriggerRestart(object sender, EventArgs e)
{
Application.Restart();
}
private static void TriggerConfigure(object sender, EventArgs e)
{
(new Configuration()).Show();
}
private static void TriggerExit(object sender, EventArgs e)
{
//Application.Exit();
Environment.Exit(0);
}
public static void TriggerRefresh(object sender, EventArgs e)
{
if (AppleKeyboardHID2.Registered)
AppleKeyboardHID2.Shutdown();
AppleKeyboardHID2.Start();
}
}
}

View file

@ -0,0 +1,22 @@
<Window x:Class="AppleWirelessKeyboard.Views.Configuration"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:properties="clr-namespace:AppleWirelessKeyboard.Properties"
Title="Configuration" Height="300" Width="300">
<Window.Resources>
<properties:Settings x:Key="Settings"/>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="Swap Control and Fn:" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,6,0" Foreground="Gray"/>
<CheckBox Name="swapCtrlFn" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding Source={StaticResource Settings}, Path=Default.SwapCtrlFn}"/>
</Grid>
</Window>

View file

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace AppleWirelessKeyboard.Views
{
/// <summary>
/// Interaction logic for Configuration.xaml
/// </summary>
public partial class Configuration : Window
{
public Configuration()
{
InitializeComponent();
}
}
}

View file

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using CoreAudioApi;
namespace AppleWirelessKeyboard
{
public static class VolumeControl
{
static VolumeControl()
{
MMDeviceEnumerator enumerator = new MMDeviceEnumerator();
MMDevice device = enumerator.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
Controller = device.AudioEndpointVolume;
}
private static AudioEndpointVolume Controller = null;
public static void ToggleMute()
{
Controller.Mute = !Controller.Mute;
if (Controller.Mute)
NotificationCenter.NotifyMuteOff();
else
NotificationCenter.NotifyMuteOn();
}
public static void VolumeUp()
{
if (Controller.MasterVolumeLevelScalar > 0.9375f)
Controller.MasterVolumeLevelScalar = 1.0f;
else Controller.MasterVolumeLevelScalar += 0.0625f;
NotificationCenter.NotifyVolumeLevel((int)(Controller.MasterVolumeLevelScalar / 0.0625));
}
public static void VolumeDown()
{
if (Controller.MasterVolumeLevelScalar < 0.0625)
{
Controller.MasterVolumeLevelScalar = 0;
NotificationCenter.NotifyNoVolume();
}
else
{
Controller.MasterVolumeLevelScalar -= 0.0625f;
NotificationCenter.NotifyVolumeLevel((int)(Controller.MasterVolumeLevelScalar / 0.0625));
}
}
}
}

Some files were not shown because too many files have changed in this diff Show more