Toggling Focus Assist mode in Win 10 Programmatically

一曲冷凌霜 提交于 2021-02-07 05:53:28

问题


There are a few unanswered questions to this pretty much everywhere I've looked so I suppose I should add mine to the tally.

I am looking to toggle Focus Assist mode in Win 10 programmatically and have thus far been unsuccessful with finding much documentation on this in both official and unofficial channels.

If I am not able to toggle focus assist programmatically, I will need to essentially emulate the same behavior meaning, that I will need to intercept and squelch incoming notifications until it is turned off and then display notifications that were silenced during this period.

It seems the only path available right now is to write some c++ using reversed WNF information and then pray it won't break in an update. Before I go down that rabbit hole I figured I'd see if anyone has done this or maybe can point me to a resource I haven't considered.

The notification listener is great and gives me access to said notifications to fulfills my secondary requirement but it does not allow me to silence them as they come in since it runs in parallel with vs interrupts the flow of the notification.

For folks that ask this question in the future, I've found these helpful:

  • Notification listener: Access all notifications
  • Is there a way to detect changes in Focus Assist (formerly Quiet Hours)
  • Playing with the Windows Notification Facility (WNF)
  • WNF IDs from perf_nt_c.dll (adk version 17692)

回答1:


I am looking to toggle Focus Assist mode in Win 10 programmatically and have thus far been unsuccessful

Currently, UWP does not provide such api to switch Focus Assist mode programmatically . If you do want this feature, please feel free to ask for this feature on UserVoice.




回答2:


You can toggle the mode using WNF mechanism.

Generate binary content of the file "0" = 00 00 00 00 (hex) and file "1" = 02 00 00 00 (hex)

For example, in git bash

echo -n -e "\x00\x00\x00\x00" > 0
echo -n -e "\x02\x00\x00\x00" > 1

Clone repository: https://github.com/ionescu007/wnfun

pip install Pywin32
pip install hexdump

Turn on the Priority mode

python WnfDump.py -w WNF_SHEL_QUIET_MOMENT_SHELL_MODE_CHANGED 1

Turn off Focus Assist

python WnfDump.py -w WNF_SHEL_QUIET_MOMENT_SHELL_MODE_CHANGED 0

If you find a way to turn on the "Alarms only" mode, let me know.

You can use the same technique C++ as well.

EDIT: Actually, the command activates mode that is set for the "full screen mode" and the file content 01 00 00 00, would activate the "game mode". If both are turned off, the command will have no effect.



来源:https://stackoverflow.com/questions/55477041/toggling-focus-assist-mode-in-win-10-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!