Windows Mobile devices, both Smartphone and Pocket PC support Speakerphone functionality. When operating through the Phone application the end user can toggle the state, up until now there has been no documented way to achieve this through code. Last year I investigated the issue on behalf of one of my readers and failed on several attempts at simulating a press-and-hold of the green phone button. It turns out that the device issues a specific key constant to change the state, and this can be simulated through code. It also turns out that the constant is equivalent to VK_F16 (thats Keys.F16 for managed code). I’ve wrapped up the necessary P/Invoke into the following code:-
public sealed class SpeakerPhone
{
private SpeakerPhone() { }
/// <summary>
/// Toggles the SpeakerPhone state.
/// </summary>
public static void Toggle()
{
//keydown
NativeMethods.keybd_event((byte)Keys.F16, 0, 0, 0);
//keyup
NativeMethods.keybd_event((byte)Keys.F16, 0, NativeMethods.KEYEVENTF_KEYUP, 0);
}
internal static class NativeMethods
{
internal const int KEYEVENTF_KEYUP = 0x0002;
[System.Runtime.InteropServices.DllImport(“coredll.dll”)]
internal static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
}
}
Since this just toggles the state, you can’t determine the current state at any particular time. This code has been tested on Windows Mobile 5.0 and beyond (It possibly works on Windows Mobile 2003 but I haven’t tested), it doesn’t work on the Windows Mobile 5.0 Emulators as Speakerphone isn’t implemented. I was able to establish a call on speakerphone using the following code:
Microsoft.WindowsMobile.Telephony.Phone p = new Microsoft.WindowsMobile.Telephony.Phone();
p.Talk(“01234567890”);
SpeakerPhone.Toggle();
Once the call is ended the speakerphone state is restored on subsequent calls.