jerryh91
jerryh91

Reputation: 1795

How to trigger Cortana Programmatically?

Is there a way to use VoiceCommand methods used to programaticlly trigger Cortana as if the Cortana has registered "Hey Cortana" to begin listening?

Upvotes: 3

Views: 651

Answers (2)

natidea
natidea

Reputation: 31

I had this same question, but for Windows 10. Found a solution: on Windows 10, you can trigger Cortana with Win + C key stroke combination. To get this working programmatically, you would need interop with the Win32 SendInput method. Fortunately there is a NuGet package Windows Input Simulator, that does just this:

Install-Package InputSimulator

With that installed I was able to trigger Cortana from a WPF app using:

var sim = new InputSimulator();
sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.VK_C);

Upvotes: 1

DevEnitly
DevEnitly

Reputation: 393

It is not possible the closest you can get is using something like this:

async static void LaunchCortana(bool untrusted, string searchText)
    {
        // The URI to launch
        string uriToLaunch = @"http://www.bing.com/";
        searchText = "search?q=" + searchText.Replace(" ", "+");
        var uri = new Uri(uriToLaunch + searchText);

        // Set the option to show a warning
        var options = new Windows.System.LauncherOptions();
        options.TreatAsUntrusted = untrusted;

        // Launch the URI with a warning prompt
        var success = await Windows.System.Launcher.LaunchUriAsync(uri, options);

        if (success)
        {
            // URI launched
        }
        else
        {
            // URI launch failed
        }
    }

or

        await Launcher.LaunchUriAsync(new Uri("bing://home"));

It works in Windows Phone 8.x only and utilizes the fact that Cortana disables Bing.com , but you can't use it to launch Cortana commands. It will just starts a Web search.

Upvotes: 0

Related Questions