As we know, if we press the F8(Play) keyboard button, iTunes or Music .app opened in default on macOS. Some Swift classes are available for preventing this keyboard shortcut but they are not compatible with C# & Xamarin. Fore example, Spotify macOS app have this ability. If you press play button on UI once, it takes the control over iTunes and handles the "Play" button key event.
I have this code block. However, macOS cannot fires the code block because of iTunes. The other keys like letters and numbers working correctly:
private NSEvent KeyboardEventHandler(NSEvent theEvent)
{
ushort keyCode = theEvent.KeyCode;
if(keyCode== 100) //rbKeyF8 100 is play button.
{
switch (isplaying)
{
case true:
StopMusic();
break;
case false:
PlayMusic();
break;
}
}
// NSAlert a = new NSAlert()
//{
// AlertStyle = NSAlertStyle.Informational,
// InformativeText = "You press the " + keyCode + " button :)",
// MessageText = "Hi"
//};
//a.RunModal();
return theEvent;
}
How can we do it with C# ? Thanks.