How to get macOS keyboard shortcuts set in System Preferences programmatically?

前端 未结 1 596
予麋鹿
予麋鹿 2021-01-14 10:56

On macOS the key combination CMD+Backtick is used to cycle through the open windows of an application when using an english keyboard. On German keyboards for ex

相关标签:
1条回答
  • 2021-01-14 11:04

    I can't test right now the answer ... but I would first try to popen the defaults command like:

    HFILE file;
    if (!(file = popen("defaults read NSGlobalDomain NSUserKeyEquivalents", "r")))
    {
        return nullptr;    
    }
    const int MAX_BUF_SIZE = 512;
    char temp[MAX_BUF_SIZE+1] = "";
    while (fgets(temp, MAX_BUF_SIZE, file) > 0)
    {
        printf("%s",temp);
        memset(temp, 0, MAX_BUF_SIZE+1);
    }
    pclose(file);
    

    Here I just printf its output but you will likely want to parse it.

    0 讨论(0)
提交回复
热议问题