<p><code>win32api</code>只是底层windows低级库的接口。
请参见<a href="http://msdn.microsoft.com/en-us/library/ms646293%28v=vs.85%29.aspx" rel="noreferrer">^{<cd2>} Function</a>:</p>
<blockquote>
<p>Determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState.</p>
<p>Syntax</p>
</blockquote>
<pre><code>SHORT WINAPI GetAsyncKeyState(
__in int vKey
);
</code></pre>
<blockquote>
<p>Return Value</p>
<p>Type: <code>SHORT</code></p>
<p>If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. </p>
</blockquote>
<p>注意,返回值是位编码的(不是<code>boolean</code>)。
为了获得<code>vKey</code>值,应用程序可以使用<code>win32con</code>模块中的虚拟键代码常量。</p>
<p>例如,测试“CAPS LOCK”键:</p>
<pre><code>>>> import win32api
>>> import win32con
>>> win32con.VK_CAPITAL
20
>>> win32api.GetAsyncKeyState(win32con.VK_CAPITAL)
0
>>> win32api.GetAsyncKeyState(win32con.VK_CAPITAL)
1
</code></pre>
<p>简单字母的虚拟键常数是ASCII码,
因此,测试“H”键(键被按下)的状态将如下所示:</p>
<pre><code>>>> win32api.GetAsyncKeyState(ord('H'))
1
</code></pre>