<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5] Keyboard state without a display</title>
		<link>http://www.allegro.cc/forums/view/617565</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 25 Sep 2018 17:35:01 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is it possible to use <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_keyboard_state"><span class="a">al_get_keyboard_state</span></a><span class="k2">(</span><span class="k2">)</span></span> without a display or with no display focused?. I&#39;ve tried and it seems it only works with a display and only if it is the currently active window.</p><p>Needless to say, keyboard events won&#39;t work without a display either.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kenmasters1976)</author>
		<pubDate>Wed, 19 Sep 2018 23:50:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/617565/1039278#target">kenmasters1976</a> said:</div><div class="quote"><p>
I&#39;ve tried and it seems it only works with a display and only if it is the currently active window.
</p></div></div><p>
I think that&#39;s Allegro&#39;s choice of API (which is not atypical). You can only process EVENT&#39;s that are actually sent to your window because that&#39;s the normal &quot;windows/GUI&quot; expectation. There are global API&#39;s for keyboard events but it&#39;s not coming from DirectX, IIRC.</p><p>According to here, DirectX doesn&#39;t support global keys. But they could be wrong.</p><p><a href="https://hydrogenaud.io/index.php/topic,63872.0.html">https://hydrogenaud.io/index.php/topic,63872.0.html</a></p><p>In my google searching &quot;DirectX&quot; and &quot;global hotkeys&quot; came up with almost no useful results.</p><p>[edit] If you have a few specific keys, there is RegisterHotKey. Otherwise, it looks like you hook into a low-level keyboard handler. Per this:</p><p><a href="https://stackoverflow.com/questions/5259322/catching-global-hotkeys-windows">https://stackoverflow.com/questions/5259322/catching-global-hotkeys-windows</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Chris Katko)</author>
		<pubDate>Thu, 20 Sep 2018 06:48:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Allegro&#39;s KB state comes from the window events. You need a window to get events. Hence, you need a window to get KB input.</p><p>Otherwise, you need to do what Katko suggested, and hook the low level keyboard process.</p><p>Just google code for a keylogger. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 20 Sep 2018 17:19:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for your replies. I wanted to use Allegro for a background process (no display) that would stop whenever a key is pressed. I guess it&#39;s not possible with Allegro alone, then, and I will have to look into those low-level routines. Thanks for the links.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Just google code for a keylogger. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div></div><p>Yeah, I guess that&#39;s kinda what I need, thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kenmasters1976)</author>
		<pubDate>Fri, 21 Sep 2018 02:17:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It looks like you might be able to capture key presses with WM_INPUT as well, even if the window is not in the foreground, as alluded to by :</p><div class="quote_container"><div class="title"><a href="https://docs.microsoft.com/en-us/windows/desktop/inputdev/wm-input">MSDN WM_INPUT message</a> said:</div><div class="quote"><p>
Parameters</p><p>wParam</p><p>    The input code. This parameter can be one of the following values.<br />    Value 	Meaning</p><p>    RIM_INPUT<br />    0</p><p>    	Input occurred while the application was in the foreground. The application must call DefWindowProc so the system can perform cleanup.</p><p>    <b>RIM_INPUTSINK</b><br />    1</p><p>    	<i>Input occurred while the application was not in the foreground. The application must call DefWindowProc so the system can perform the cleanup.</i></p><p>lParam</p><p>    A handle to the RAWINPUT structure that contains the raw input from the device.
</p></div></div><p>

So you might want to look into Raw Input :<br /><a href="https://docs.microsoft.com/en-us/windows/desktop/inputdev/raw-input">https://docs.microsoft.com/en-us/windows/desktop/inputdev/raw-input</a></p><p>Low level hooks have some restrictions and caveats. IIRC, back when I wrote ManyMouse, I had to hook the low level mouse handler, but it had to be stored inside a dll for it to work properly, at least according to Microsoft.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 22 Sep 2018 20:50:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for the link and sorry for the late reply.</p><p>I found <a href="https://github.com/kwhat/libuiohook">this library</a> which offers &quot;A multi-platform C library to provide global keyboard and mouse hooks from userland&quot;. I&#39;m currently trying it on Linux.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kenmasters1976)</author>
		<pubDate>Tue, 25 Sep 2018 02:08:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What are you trying to do?<br /><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Doctor Cop)</author>
		<pubDate>Tue, 25 Sep 2018 17:35:01 +0000</pubDate>
	</item>
</rss>
