Note that there are some explanatory texts on larger screens.

plurals
  1. POANE C API - Converting uint8_t String to MFC virtual key code
    primarykey
    data
    text
    <p>First, I apologize in an advance as this may be a bit of a vague question since as of now I don't have all too much to go off of.</p> <p>I'm in the process of writing an ANE that takes an AS3 String and passes it off to a MFC C++ dll that inputs it to Windows using <code>SendInput</code></p> <p><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx</a></p> <p>Now I'm not yet too familiar with the Flash C API but I'm currently under the impression that Strings passed over from AS3 are typed as <code>const uint8_t</code> on the C side and populated using <code>FREGetObjectAsUTF8</code>. I'm using the following code to accomplish this: </p> <pre><code>uint32_t len; cost uint8_t str; FREGetObjectAsUTF8(argv[0], &amp;len, &amp;str); //string is a single char </code></pre> <p>To send the keystroke I'm using this</p> <pre><code>void KeyboardHelper::sendKeyStroke(int vk){ INPUT input = {0}; input.type = INPUT_KEYBOARD; input.ki.wScan = 0; //not scanning for hardware key input.ki.time = 0; input.ki.dwExtraInfo = 0; //virtual key code for the key we want to press input.ki.wVk = vk; input.ki.dwFlags = 0; //keypress SendInput(1, &amp;input, sizeof(input)); } </code></pre> <p><code>input.ki.wVk</code> is looking for the hex value of the keycode to be sent. MSDN has a list of all the hex values and associated keystrokes here:</p> <p><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx</a></p> <p>This code does work and I am able to input a keystroke from my AIR app its just not the correct key. Since you can convert <code>uint8_t</code> to <code>int</code> my current incorrect code is calling <code>sendKeyStroke</code> like this:</p> <pre><code>FREGetObjectAsUTF8(argv[0], &amp;len, &amp;str); //line from above keyboardHelper-&gt;sendKeyStroke(int(str)); </code></pre> <p>Again, this does seem to work, but I just get a random input.</p> <p>I'm also not really even sure what the value of <code>str</code> or <code>int(str)</code> are since I haven't figured out how to step into this code when its being called from AIR. As a side-note, if anyone knows anything about debugging ANE's feel free to let me know :) (I'm using VS2012)</p> <p><strong>I guess the root of this question comes down to this:</strong></p> <p>Is it possible to convert a <code>const uint8_t</code> to a corresponding virtual key code? In this case I will only be dealing with one keystroke at a time.</p> <p>If not it also seems like <code>KEYBDINPUT wScan</code> takes a unicode character if <code>dwFlags</code> is set to <code>KEYEVENTF_UNICODE</code>. Would it be possible to convert <code>const uint8_t</code> to a <code>WORD</code> type I could use in <code>wScan</code>?</p> <p>I've been using the following MSDN docs as reference:</p> <p>KEYBDINPUT: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646271%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/ms646271%28v=vs.85%29.aspx</a></p> <p>SendInput: <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx</a></p> <p>Thanks!</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.
 

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