Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>41</code> and <code>0x41</code> are two completely different values. The second one, <code>0x41</code> is hex for the decimal value 65, which is the ASCII code for 'A'. But I'm guessing you already know this since you initialise <code>i</code> to 65 (capital ASCII letters and VK codes match up).</p> <p>Anyway your code almost works ok to an extent, assuming that you're trying to log key presses. Long story short is your loop delay is <em>way</em> too long, for it to iterate through every character it takes <code>200ms * 26 = 5.2 seconds</code>. Therefore if you type "AAAB" within 5.2 seconds only "AB" will be registered. But if the delay is too short then you might register a press more than once.</p> <p>Read the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646293%28v=vs.85%29.aspx" rel="nofollow">documentation for GetAsyncKeyState</a> for more info.</p> <p>Anyway I'd probably choose a different function as mentioned in the remarks of the documentation above, something like <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646299%28v=vs.85%29.aspx" rel="nofollow">GetKeyboardState</a>, as you'd usually use something like <code>GetAsyncKeyState</code> for registering key presses of hotkeys or something similar. ie. <code>GetAsyncKeyState</code> is good for wanting to know if a key <em>was</em> pressed, rather than how many times, the order of the presses, etc. A loop the way you have it just seems really prone to problems.</p> <p>Also, don't do anything stupid logging keys...</p> <p><strong>EDIT:</strong> Actually <code>GetKeyboardState</code> still isn't that good of a solution. Setting a keyboard hook with <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx" rel="nofollow">SetWindowsHookEx</a> would be a much better alternative. You could use the <code>WH_KEYBOARD_LL</code> hook type to set a low level keyboard hook with a <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms644985%28v=vs.85%29.aspx" rel="nofollow">LowLevelKeyboardProc</a> callback.</p> <p>I did some Googling and there's an open-source macro program, <a href="http://www.autohotkey.com/" rel="nofollow">AutoHotkey</a> that uses this method, which I guess you could take a look at if you wanted.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload