<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Возможность вкл/выкл блокировки ввода с клавиатуры]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=14033&amp;type=atom" />
	<updated>2018-08-13T17:08:12Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=14033</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Возможность вкл/выкл блокировки ввода с клавиатуры]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=127896#p127896" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Gutalin пишет:</cite><blockquote><p>но все равно блокирует все окна:</p></blockquote></div><p>Можно, чтобы только одно блокировало:<br /></p><div class="codebox"><pre><code>#Persistent
l:=0
Gui, add, edit, vblblbl
 Gui, add, Button, gLock, вкл/выкл
  Gui, show, w200 h200, Окно
 WinTtl = Окно
Return

Lock:
{
if l=1
    {
  SetTimer, bd, Off
  SendEvent, {vkFF 2}
    l:=0
    }
Else if l=0
    {
   SetTimer, Block, -1
   l:=1
    }
  }
return

Block:
    IfWinActive, %WinTtl%
    SetTimer, bd, 1
    Input, InputKeys,, {vkFF 2}
    l:=0
    Return

Guiclose:
ExitApp

F12::
{
if l=1
    {
  SetTimer, bd, Off
  SendEvent, {vkFF 2}
    l:=0
    }
Else if l=0
   {
   SetTimer, Block, -1
   l:=1
   }
 }
Return

F10::ExitApp

bd:
   SetTimer, t, -1
   IfWinNotActive, %WinTtl%
   SendEvent, {vkFF 2}
   Exit
Return

t:
SetTimer, bd, Off
Return</code></pre></div><p>Как вы проще решили эту проблему?</p>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2018-08-13T17:08:12Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=127896#p127896</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Возможность вкл/выкл блокировки ввода с клавиатуры]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=127842#p127842" />
			<content type="html"><![CDATA[<p>Проблема была решена проще.<br />Всем спасибо за ответы!</p>]]></content>
			<author>
				<name><![CDATA[Gutalin]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39002</uri>
			</author>
			<updated>2018-08-12T14:02:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=127842#p127842</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Возможность вкл/выкл блокировки ввода с клавиатуры]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=127836#p127836" />
			<content type="html"><![CDATA[<p><strong>svoboden</strong>, да, всё работает очень хорошо и блокирует ввод во всех окнах. <br />Почему это не работает?<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#UseHook
#Persistent
l:=0
Gui, add, edit, vblblbl
Gui,add,Button, gLock, вкл/выкл
Gui,show, w200 h200,Окно
WinTtl=Окно
 Return


Lock:
if (l=1)
    {
    SendEvent, {vkFF}
    l:=0
    }
Else if (l=0)
    {
   SetTimer, Block, -1
   l:=1
    }
return

Block:
While l=0
{
IfWinNotActive, %WinTtl%
    break
else IfWinActive, %WinTtl%
Input, InputKeys,, {vkFF}
}
Return


Guiclose:
ExitApp

F10::ExitApp</code></pre></div></div></div><p>Add: <br />l:=1 идёт сразу после выполнения block и это всё ломает<br />AdD2:<br />Вроде разобрался и работает, но всеравно блокирует все окна:<br /></p><div class="codebox"><pre><code>
#UseHook
#Persistent
l:=1
Gui, add, edit, vblblbl
Gui,add,Button, gLock, вкл/выкл
Gui,show, w200 h200,Окно
WinTtl=Окно
 Return


Lock:
if (l=1)
    {
    l:=0
    SetTimer, Block, -1
    }
Else if (l=0)
    {
    l:=1
    SendEvent, {vkFF}
    }

return

Block:
While l=0
{
IfWinNotActive, %WinTtl%
    break
else IfWinActive, %WinTtl%
Input, InputKeys,, {vkFF}
}
Return


Guiclose:
ExitApp

F10::ExitApp
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Gutalin]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39002</uri>
			</author>
			<updated>2018-08-12T10:48:27Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=127836#p127836</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Возможность вкл/выкл блокировки ввода с клавиатуры]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=127831#p127831" />
			<content type="html"><![CDATA[<div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><p>Input не особо надёжен, тем более для блокировки.<br />Пример для нескольких окон по классу и exe.<br /></p><div class="codebox"><pre><code>
Global Arr := {Notepad:&quot;notepad.exe&quot;
			,CalcFrame:&quot;calc.exe&quot;} 
Run Notepad
Run Calc
Return

Esc::ExitApp

EVENT_SYSTEM_FOREGROUND(hWinEventHook, event, hwndid, idObject, idChild, dwEventThread, dwmsEventTime) {
	Static _ := SetWinEventHook(&quot;EVENT_SYSTEM_FOREGROUND&quot;, 0x0003)
	If (idObject || idChild)
		Return
	WinGetClass, Class, % &quot;ahk_id &quot; hwndid
	If Arr.HasKey(Class) || SetHook(0)
	{
		WinGet, Process, ProcessName, % &quot;ahk_id &quot; hwndid  
		SetHook(Arr[Class] = Process)   
	}
} 

SetHook(On) {
	Static hHookKeybd, _ := OnExit(Func(&quot;SetHook&quot;).Bind(0))
	DllCall(&quot;UnhookWindowsHookEx&quot;, Ptr, hHookKeybd)
	If On
		hHookKeybd := DllCall(&quot;SetWindowsHookEx&quot;
			, Int, WH_KEYBOARD_LL := 13
			, Ptr, RegisterCallback(&quot;LowLevelKeyboardProc&quot;, &quot;Fast&quot;)
			, Ptr, DllCall(&quot;GetModuleHandle&quot;, UInt, 0, Ptr)
			, UInt, 0, Ptr)
}

LowLevelKeyboardProc(nCode, wParam, lParam) {
   Return 1
}

SetWinEventHook(EventProc, eventMin, eventMax = 0)  {
	Return DllCall(&quot;SetWinEventHook&quot;
				, &quot;UInt&quot;, eventMin, &quot;UInt&quot;, eventMax := !eventMax ? eventMin : eventMax
				, &quot;Ptr&quot;, hmodWinEventProc := 0, &quot;Ptr&quot;, lpfnWinEventProc := RegisterCallback(EventProc, &quot;F&quot;)
				, &quot;UInt&quot;, idProcess := 0, &quot;UInt&quot;, idThread := 0
				, &quot;UInt&quot;, dwflags := 0x0|0x2, &quot;Ptr&quot;)	;	WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS
}
</code></pre></div></div></div><p>ADD:<br />Не внимательно прочитал, то что надо по кнопке снимать перехват.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2018-08-12T07:34:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=127831#p127831</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Возможность вкл/выкл блокировки ввода с клавиатуры]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=127828#p127828" />
			<content type="html"><![CDATA[<p>Так можно, по нажатию кнопки F12 вкл/выкл:<br /></p><div class="codebox"><pre><code>#UseHook
#Persistent
l:=0
Gui, add, edit, vblblbl
Gui,add,Button, gLock, вкл/выкл
Gui,show, w200 h200,Окно
WinTtl=Окно
 Return


Lock:
if (l=1)
    {
  SendEvent, {vkFF 2}
    l:=0
    }
Else if (l=0)
    {
   SetTimer, Block, -1
   l:=1
    }
return

Block:
    WinWaitActive, %WinTtl%        
    Input, InputKeys,, {vkFF}    
    Return

Guiclose:
ExitApp

F12::
if (l=1)
    {
  SendEvent, {vkFF 2}
    l:=0
    }
Else if (l=0)
    {
   SetTimer, Block, -1
   l:=1
    }
Return

F10::ExitApp</code></pre></div>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2018-08-12T01:42:04Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=127828#p127828</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: Возможность вкл/выкл блокировки ввода с клавиатуры]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=127827#p127827" />
			<content type="html"><![CDATA[<p>Есть код в коллекции:<a href="http://forum.script-coding.com/viewtopic.php?pid=9712#p9712">Блокировка ввода с клавиатуры для указанного окна</a>, но мне нужно приостановить его работу по нажатию кнопки.<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#Persistent
Gui, add, edit, vblblbl
l:=0
Gui,add,Button, gLock, вкл/выкл
Gui,show, w200 h200,Окно
WinTtl=Окно
 Return

Lock:
{
if l=1
	{
    SendEvent, {vkFF}
    l:=0 
	}
else if l=0
	{
   SetTimer, BlockKbd, 100
   l:=1
	}
}
return

BlockKbd:
    SetTimer, BlockKbd, Off

    Loop 
    {
        WinWaitActive, %WinTtl%        
        SetTimer, UnBlockKbd, 100    
        Input, InputKeys,, {vkFF}    
    }
    Return

UnBlockKbd:
    SetTimer, UnBlockKbd, Off
    WinWaitNotActive, %WinTtl%  
    SendEvent, {vkFF}       
    Return
    
F10::ExitApp

Guiclose:
ExitApp</code></pre></div></div></div><p>Работает как-то одноразово, ну решил:&quot;Нужно проверять значение переменной l&quot;<br /></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header" data-lang-open="открыть спойлер" data-lang-close="скрыть спойлер"><strong>+</strong>&nbsp;открыть спойлер</div><div class="fancy_spoiler"><div class="codebox"><pre><code>#Persistent
WinTtl=Окно
  SetTimer, BlockKbd, 100
Gui, add, edit, vblblbl
l:=0
Gui,add,Button, gLock, вкл/выкл
Gui,show, w200 h200,Окно

 Return

Lock:
{
if l=1
    l:=0 
else if l=0
   l:=1
}
return

BlockKbd:
    SetTimer, BlockKbd, Off

    Loop 
    {
        WinWaitActive, %WinTtl%        
        SetTimer, UnBlockKbd, 100  
        if l=1
			SetTimer, UnBlockKbd, 100        
        else
        Input, InputKeys,, {vkFF}    
    }
    Return

UnBlockKbd:
    SetTimer, UnBlockKbd, Off
    Loop
    {
    if l=0 
		SendEvent, {vkFF} 
    else ifWinNotActive, %WinTtl% 
        SendEvent, {vkFF} 
}
    Return
    
F10::ExitApp

Guiclose:
ExitApp</code></pre></div></div></div><p>Как сделать, чтобы можно было вкл/выкл возможность скрипта блокировать ввод?</p>]]></content>
			<author>
				<name><![CDATA[Gutalin]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39002</uri>
			</author>
			<updated>2018-08-11T21:55:07Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=127827#p127827</id>
		</entry>
</feed>
