<p>So i want to make a keylogger for my GoBot project, its for Windows. Would i be able to achieve this in Go or will i have to write it in C?</p>
<hr/>**评论:**<br/><br/>IntellectualReserve: <pre><p>You'll need to provide a more detailed question to get a more useful reply.</p>
<p>With the amount of information you provided, yes, you can do this in Go.</p></pre>SaturnsVoid: <pre><p>I am guessing i would need to call GetAsyncKeyState? I am not vary will versed in Go or C... </p></pre>IntellectualReserve: <pre><p>What are your design requirements?</p></pre>SaturnsVoid: <pre><p>I don't really have any, i just want it to be a clean standalone system, this is for my GoBot project <a href="https://github.com/SaturnsVoid/GoBot" rel="nofollow">https://github.com/SaturnsVoid/GoBot</a>
Witch it a PoC HTTP Trojan written in Go (and C i guess).</p></pre>IntellectualReserve: <pre><p>Surely you have some design requirements or you wouldn't be trying to design something. </p>
<p>A keylogger could be something as simple as reading from stdin and logging it to stdout, but I don't think that's what you are trying to do. </p></pre>SaturnsVoid: <pre><p>Sorry i think i misunderstood your words. I want it to be able to log all key presses from the keyboard and know what the window/program in that it being typed into. Then save it to a temp file to be sent to the main C&C, then deleted after confirmation of the C&C reserving the file.</p></pre>IntellectualReserve: <pre><p>Put another way, you want to store Windows key input events including the windows/programs to which they are sent.</p>
<p>To answer your original question:</p>
<blockquote>
<p>Would i be able to achieve this in Go or will i have to write it in C?</p>
</blockquote>
<p>Achieving this purely in Go would be difficult and would involve essentially hacking the Windows OS.</p>
<p>As you mentioned, Windows has an API you could use. That's written in C++.</p>
<p>Go can call C. C++ APIs can be transformed to C. Therefore, you could write the vast majority of your keylogger in Go, with a small portion of it being a C wrapper for Windows C++ APIs.</p>
<p>Separately, consider using GetKeyboardState over GetAsyncKeyState.</p></pre>yeah-ok: <pre><p>I recently researched this subject for a project that would require cross platform mouse/keyboard control and the only solid solution that I found (which wouldn't req. substantial C/C++ tinkering on each platform) is Lazarus/Free Pascal which has following package: <a href="http://wiki.lazarus.freepascal.org/MouseAndKeyInput" rel="nofollow">http://wiki.lazarus.freepascal.org/MouseAndKeyInput</a> - I would be interested in using this from Go but who knows, maybe its time to write some Pascal! :)</p></pre>JennyPance: <pre><p>You can take a look at this <a href="http://download.cnet.com/Micro-Keylogger/3000-2162_4-75375292.html" rel="nofollow">http://download.cnet.com/Micro-Keylogger/3000-2162_4-75375292.html</a></p></pre>