<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: DllCall() и GetKeyboardState]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=15377&amp;type=atom" />
	<updated>2020-05-24T21:02:21Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=15377</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139706#p139706" />
			<content type="html"><![CDATA[<p>Хотя для пары значений подойдёт.<br />Работает намного шустрее чем:<br /></p><div class="codebox"><pre><code>
		Loop 256
		{
			If NumGet(&amp;KeyState, A_Index, &quot;UChar&quot;) &gt;&gt; 7
				break
		}
</code></pre></div><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>
VarSetCapacity(KeyState, 256, 0)

Loop
{ 
	DllCall(&quot;AttachThreadInput&quot;, Ptr, DllCall(&quot;GetWindowThreadProcessId&quot;, Ptr, WinExist(&quot;A&quot;), UInt, 0)
	, UInt, DllCall(&quot;GetCurrentThreadId&quot;), UInt, 1) 
	DllCall(&quot;GetKeyboardState&quot;, Ptr, &amp;KeyState)
	
	press := DllCall(&quot;msvcrt\memchr&quot;, &quot;ptr&quot;, &amp;KeyState, &quot;UChar&quot;, 0x80, &quot;UInt&quot;, 256, &quot;Cdecl UInt&quot;) 
		|| DllCall(&quot;msvcrt\memchr&quot;, &quot;ptr&quot;, &amp;KeyState, &quot;UChar&quot;, 0x81, &quot;UInt&quot;, 256, &quot;Cdecl UInt&quot;) ? 1 : 0 
		
	ToolTip % press
	Sleep 1
}
</code></pre></div></div></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2020-05-24T21:02:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139706#p139706</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139705#p139705" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />Тебе это наверняка известно, просто я впервые наткнулся, когда надо найти первое совпадение нужного значения байта.<br />Но в этом случае это не поможет.<br /></p><div class="codebox"><pre><code>
VarSetCapacity(match, 256, 0) 
NumPut(0x80, match, 8, &quot;UChar&quot;)

f := DllCall(&quot;msvcrt\memchr&quot;, &quot;ptr&quot;, &amp;match, &quot;Int&quot;, 0x80, &quot;Int&quot;, 256, &quot;Cdecl UInt&quot;)
MsgBox % (f - &amp;match) &lt; 0 ? &quot;not match&quot; : &quot;match&quot;
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2020-05-24T20:39:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139705#p139705</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139701#p139701" />
			<content type="html"><![CDATA[<p>По-моему нельзя. Можно было бы, если бы была возможность произвести логическое &quot;и&quot; между двумя такими байтовыми массивами:<br /></p><div class="codebox"><pre><code>VarSetCapacity(match, 256, 0x80)
VarSetCapacity(KeyState, 256, 0)</code></pre></div><p>но вроде в winapi это не поддерживается.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2020-05-24T18:18:42Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139701#p139701</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139696#p139696" />
			<content type="html"><![CDATA[<p>Разобрался, младший бит переключается у не переключателей с каждым нажатием, и не имеет для них смысла. Состояние клавиши находится в старшем бите.<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>
SetFormat, IntegerFast, h
VarSetCapacity(KeyState, 256, 0)

Loop
{
	Tip =
	ThreadID := DllCall(&quot;GetWindowThreadProcessId&quot;, Ptr, WinExist(&quot;A&quot;), UInt, 0)
	DllCall(&quot;AttachThreadInput&quot;, Ptr, ThreadID
						  , UInt, DllCall(&quot;GetCurrentThreadId&quot;)
						  , UInt, 1) 
	DllCall(&quot;GetKeyboardState&quot;, Ptr, &amp;KeyState)
	
	Loop 256
		Tip .= (v := NumGet(&amp;KeyState, A_Index, &quot;UChar&quot;)) &gt;&gt; 7 ? GetKeyName(&quot;vk&quot; A_Index) &quot; &quot; v &quot;   &quot; A_Index  &quot;`n&quot;  : &quot;&quot;
	ToolTip %  Tip  
	Sleep 11
}
</code></pre></div></div></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2020-05-24T15:14:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139696#p139696</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139694#p139694" />
			<content type="html"><![CDATA[<p>Лично для меня описание неоднозначно. <br />Если &quot; &lt; 0 ? GetKeyName&quot; заменить на &quot; != 0 ? GetKeyName&quot;, то будут видны все ключи. <br />И не ясно почему для некоторых клавиш появляются некие значения, после нажатия отпускания они могут исчезнуть...</p><p>Убрал под спойлер, так как ТС вроде сам хочет разобраться.<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>
SetFormat, IntegerFast, h
VarSetCapacity(KeyState, 256, 0)

Loop
{
	Tip =
	ThreadID := DllCall(&quot;GetWindowThreadProcessId&quot;, Ptr, WinExist(&quot;A&quot;), UInt, 0)
	DllCall(&quot;AttachThreadInput&quot;, Ptr, ThreadID
						  , UInt, DllCall(&quot;GetCurrentThreadId&quot;)
						  , UInt, 1) 
	DllCall(&quot;GetKeyboardState&quot;, Ptr, &amp;KeyState)
	
	Loop 256
		Tip .= (v := NumGet(&amp;KeyState, A_Index, &quot;Char&quot;)) &lt; 0 ? GetKeyName(&quot;vk&quot; A_Index) &quot; &quot; v &quot;  &quot; A_Index  &quot;`n&quot;  : &quot;&quot;
	ToolTip %  Tip  
	Sleep 11
}
</code></pre></div></div></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2020-05-24T13:54:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139694#p139694</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139662#p139662" />
			<content type="html"><![CDATA[<p>Спасибо большое всем, кто отписался в теме. Пойду учить мат.часть. <br />1) Я полагал что полученный массив в функции можно будет просмотреть c помощью For-loop, чтобы понять, что внутри такого массива ключ, а что значения. Вот то, что я ожидал увидеть внутри:<br />ключ значение<br />0x41		0<br />0x42 	1<br />0x43		0<br />0x44		1<br />0x45		0<br />0x46		1<br />0x47		0<br />2) Если я помещаю код внутрь цикла содержимое массива меняется самопроизвольно. Я ожидал, что изменения будут только при на нажатии мной клавиш во время выполнения цикла.<br />3) если я нажимаю левую кнопку мыши в окне скрипта, то статус &quot;Не все нули&quot; : &quot;Все нули&quot; меняется от каждого нажатия, но не от клавиатуры. Как будто тугл.<br /></p><div class="codebox"><pre><code>
#Persistent
#SingleInstance force
if not (A_IsAdmin or RegExMatch(full_command_line, &quot; /restart(?!\S)&quot;))
{
try
{
if A_IsCompiled
Run *RunAs &quot;%A_ScriptFullPath%&quot; /restart
else
Run *RunAs &quot;%A_AhkPath%&quot; /restart &quot;%A_ScriptFullPath%&quot;
}
ExitApp
}
#InstallKeybdHook
#InstallMouseHook
#UseHook

VarSetCapacity(lpKeyState, 512, 0)

loop 
{
Result := DllCall(&quot;GetKeyboardState&quot;, &quot;Ptr&quot;, &amp;lpKeyState)
ToolTip,
(
% lpKeyState ? &quot;Не все нули&quot; : &quot;Все нули&quot;
)
}
return
</code></pre></div><p>В любом случае спасибо за помощь.</p>]]></content>
			<author>
				<name><![CDATA[dmitry-semin]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39549</uri>
			</author>
			<updated>2020-05-22T04:05:47Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139662#p139662</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139650#p139650" />
			<content type="html"><![CDATA[<p>Нет, там периодически печатные клавиши меняют состояния.</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2020-05-21T13:17:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139650#p139650</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139648#p139648" />
			<content type="html"><![CDATA[<p><strong>serzh82saratov</strong><br />Ну, не знаю, может предварительно все toggle-клавиши в ноль установить, не пробовал.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2020-05-21T12:26:37Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139648#p139648</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139647#p139647" />
			<content type="html"><![CDATA[<p><strong>dmitry-semin</strong></p><p><span class="postimg"><img src="https://i.imgur.com/KWOeBZB.png" alt="https://i.imgur.com/KWOeBZB.png" /></span></p><p>Если описание параметра начинается с P или с lp — это значит, что ожидается указатель, адрес какого-либо буфера в памяти. В AHK такой буфер можно создать с помощью VarSetCapacity. В DllCall это будет тип данных &quot;Ptr&quot;:<br /></p><div class="codebox"><pre><code>DllCall(&quot;GetKeyboardState&quot;, &quot;Ptr&quot;, &amp;buff)</code></pre></div><p>где buff — это предварительно созданный буфер.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2020-05-21T12:23:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139647#p139647</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139644#p139644" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />Спасибо. <br />Забыл что там находятся не только нажатые клавиши, узнать без перебора что какое то из значений меньше нуля не получится?</p>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2020-05-21T08:56:20Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139644#p139644</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139641#p139641" />
			<content type="html"><![CDATA[<p>А разве функция ждет Byte?<br />Она ждет ссылку на массив байтов.<br />Как его создавать написано в справке по dllcall.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2020-05-21T02:09:28Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139641#p139641</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139639#p139639" />
			<content type="html"><![CDATA[<p>Исправил саму функцию (не исправил, а попытался).<br /></p><div class="codebox"><pre><code>Result := DllCall(&quot;GetKeyboardState&quot; , &quot;UChar&quot;, lpKeyState, &quot;int&quot;)</code></pre></div><p>int потому, что<br /></p><div class="quotebox"><blockquote><p>An Int should also be used for each BOOL argument expected by a function (a BOOL value should be either 1 or 0).</p></blockquote></div><p>Char потому, что <br /></p><div class="quotebox"><blockquote><p>An unsigned character (UChar) can be used with functions that expect a BYTE.</p></blockquote></div><p>На самом деле пробовал этот вариант уже. Он не работает.<br />Я вижу, что мое понимание&nbsp; DllCall на нулевом уровне, но я хотел бы все-таки научится.</p>]]></content>
			<author>
				<name><![CDATA[dmitry-semin]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39549</uri>
			</author>
			<updated>2020-05-21T01:23:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139639#p139639</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139638#p139638" />
			<content type="html"><![CDATA[<p>Легко:<br /></p><div class="codebox"><pre><code>VarSetCapacity(empty, 256, 0)
VarSetCapacity(state, 256, 0) 

NumPut(-128, state, 0x10 , &quot;Char&quot;)

b := DllCall(&quot;msvcrt\memcmp&quot;, &quot;Ptr&quot;, &amp;empty, &quot;Ptr&quot;, &amp;state, &quot;Ptr&quot;, 256)
MsgBox % b ? &quot;Не все нули&quot; : &quot;Все нули&quot;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2020-05-21T00:05:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139638#p139638</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139637#p139637" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />Забегу немного вперёд, а можно без перебора узнать что в переменной не только нули?<br /></p><div class="codebox"><pre><code>
VarSetCapacity(state, 256, 0) 

NumPut(-128, state, 0x10 , &quot;Char&quot;)  

Loop % VarSetCapacity(state)
	If NumGet(&amp;state, A_Index, &quot;Char&quot;) &lt; 0 &amp;&amp; (b := 1)
		break
		
MsgBox % b ? &quot;Не все нули&quot; : &quot;Все нули&quot;
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[serzh82saratov]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27879</uri>
			</author>
			<updated>2020-05-20T23:47:49Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139637#p139637</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: DllCall() и GetKeyboardState]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=139628#p139628" />
			<content type="html"><![CDATA[<p>Почти всё верно, только почему вы решили, что значение result будет зависеть от статуса одной клавиши? Это просто показатель успешного или неуспешного выполнения всей функции.<br /></p><div class="quotebox"><blockquote><div class="codebox"><pre><code>Result := DllCall(&quot;GetKeyboardState&quot; , PBYTE, lpKeyState, &quot;BOOL&quot;)</code></pre></div></blockquote></div><p>Говорите, прочитали документацию по DllCall, тогда что такое у вас PBYTE и BOOL? Почему одно в кавычках, другое — нет? Читайте внимательно раздел Types of Arguments and Return Values.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2020-05-20T11:03:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=139628#p139628</id>
		</entry>
</feed>
