啟動按ctrl鍵 遮蔽自動隱藏功能

网络来者發表於2024-08-20

[DllImport("User32.dll", EntryPoint = "ShowWindow")]
private static extern bool ShowWindow(IntPtr hWnd, int type);

#region 啟動按ctrl鍵 遮蔽自動隱藏功能
bool forceUpdate = (Control.ModifierKeys & Keys.Control) == Keys.Control;//按ctrl鍵啟動
if (!forceUpdate)
{
if (!System.Diagnostics.Debugger.IsAttached)
{
log("沒有按ctrl鍵啟動20秒隱藏");
_timer = new System.Timers.Timer(10 * 1000) { Enabled = true };//沒有按ctrl鍵2分鐘隱藏
//_timer.Elapsed += _timer_Elapsed;
_timer.Elapsed += (sender, e) =>
{
IntPtr hWnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
ShowWindow(hWnd, 0);
_timer.Enabled = false;
};
}
}
#endregion

相關文章