www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Basically want to make a macro script

reply "Casey" <caseham2012 gmail.com> writes:
/Long/ story short, I want to pretty much make a macro using this 
program.  I don't really have time to explain in further detail 
at the moment, but /no/ macro program out there will do what I'm 
trying to do.  I want to basically make it so that when I press a 
hotkey, it'll send an in game chat message.  Here's my code for 
the popular program AutoHotKey.

[code]
Numpad0 & Numpad1::
Send {k down}
Sleep 1
Send {k up}
SendInput We're losing Alpha{!}
SendInput {Enter}
Return
[/code]

That's a small sample of my script, but the only thing that would 
change with the rest of my script would be the message sent and 
the keybind to press it.

Basically what it's doing is listening for my hotkey to be 
pressed (in this particular example it's numpad 0 + numpad 1 for 
the message, "We're losing Alpha!", and so on and so forth for 
the rest of the numbers.)  and then activating the chat button in 
game (in this particular examle it's k for team chat), then 
sending the actual message as quickly as possible, and sending 
it.  Works perfectly in BF4, but PB (PunkBuster), the default 
anti cheat system that BF4 uses will kick me if the admins have 
that setting enabled.

I've been wanting to learn full on programming for a while, and 
I've heard a lot of things about D and how it's a pretty good 
starting point, and how it has a huge potential to expand you 
into anything.  Plus it's supposed to be pretty efficient and the 
next big thing in the programming world, so there's that.

Just for the record, I don't have a lot of experience with 
programming.  I've done it years ago (had an instructor for a Boy 
Scout Merit Badge class), but I didn't even know which language I 
was typing in.  I assume it was Python, but I can't be sure.  
Whatever I make I want it to be somewhat compatible with Linux 
eventually.  I just want to start with a binary .exe, but I do 
want my code to be compatible with Linux if I choose to compile 
it for Linux at a later date.  I don't think this should be an 
issue, but I just wanted to throw this out there.

I'm not sure which libraries I need for this, but as far as I 
know I just need the following:

Keybind listener/hotkey
Keyboard emulating/low level chat producing library
something that /wont/ be picked up as a hack/cheat by /ANYTHING/.

I don't think this should be that hard to make, but D doesn't 
really have much documentation out there as far as I can tell, so 
I figured this would be the best place to put this.

The sooner the better please.  Thanks for any/all help I receive.
Nov 11 2014
next sibling parent reply ketmar via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> writes:
On Wed, 12 Nov 2014 04:56:39 +0000
Casey via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

D has nothing to do with your task, WinAPI does. and you'll need alot
of expirience in reverse engineering, 'cause f... punkbuster shits it's
pants almost for anything. it's a rootkit, and very badly written one.
what you have to do is to fight with rootkit, making it think that it
is still functional. so learn assembler, x86 archtecture, winapi,
windows driver development, nt kernel internals and so on.

and don't even dream that it will be portable.
Nov 12 2014
next sibling parent "Israel" <tl12000 live.com> writes:
On Wednesday, 12 November 2014 at 08:02:06 UTC, ketmar via
Digitalmars-d-learn wrote:
 On Wed, 12 Nov 2014 04:56:39 +0000
 Casey via Digitalmars-d-learn 
 <digitalmars-d-learn puremagic.com> wrote:

 D has nothing to do with your task, WinAPI does. and you'll 
 need alot
 of expirience in reverse engineering, 'cause f... punkbuster 
 shits it's
 pants almost for anything. it's a rootkit, and very badly 
 written one.
 what you have to do is to fight with rootkit, making it think 
 that it
 is still functional. so learn assembler, x86 archtecture, 
 winapi,
 windows driver development, nt kernel internals and so on.

 and don't even dream that it will be portable.
punkbuster, albeit an older version and they worked just fine. If you want to go that way you will need InputSimulator from codeplex. For D i cant help as i dont know any library that allows you to take control over mouse and keyboard. In fact i think ill give this a go at some point.
Nov 12 2014
prev sibling parent "Casey" <caseham2012 gmail.com> writes:
On Wednesday, 12 November 2014 at 08:02:06 UTC, ketmar via 
Digitalmars-d-learn wrote:
 On Wed, 12 Nov 2014 04:56:39 +0000
 Casey via Digitalmars-d-learn 
 <digitalmars-d-learn puremagic.com> wrote:

 D has nothing to do with your task, WinAPI does. and you'll 
 need alot
 of expirience in reverse engineering, 'cause f... punkbuster 
 shits it's
 pants almost for anything. it's a rootkit, and very badly 
 written one.
 what you have to do is to fight with rootkit, making it think 
 that it
 is still functional. so learn assembler, x86 archtecture, 
 winapi,
 windows driver development, nt kernel internals and so on.

 and don't even dream that it will be portable.
I don't need to do this I'm pretty sure... I just need to write something that will send the chat messages as described in my first post. I don't need to rootkit PunkBuster, it's not trying to ban programs that send chat messages.... It's simply trying to ban macro programs like AutoHotKey. AHK can be used to make no recoil scripts, so they added an option so that server owners can choose to kick those players /if they want to/. Again, I'm writing a simple program to send chat messages at a lowish level once a hotkey/keybind has been pressed. All it needs is to add a delay in between the chat key presses (Like *chat key* down, then 1 ms later, chat key up)(Forgot to mention that last night), typing my actual message as quickly as possible, then to send the message. In other words, it needs to recignise my keybind, press the chat button down, then up with a small delay in between, send my message and press enter. PB nor any other program should find this as a cheating program. It's not a cheat at all. It's not a mod, hack, nor advantage that others can't do. It's not unfair, it's not too good, it's just something simple that I'm trying to make work. It doesn't need a GUI, it just needs what I've described above. No rootkits, nothing like that afaik. If it's not a hack/cheat, PB isn't going to look at it like it is one (hopefully). Thank you for your interest and reply.
Nov 12 2014
prev sibling next sibling parent reply "Israel" <tl12000 live.com> writes:
On Wednesday, 12 November 2014 at 04:56:40 UTC, Casey wrote:

also, you came to the right place. PB is extremely paranoid and
even more so about autohokey, so if you program your own native
macro, its not very likely it will catch it.
Nov 12 2014
parent reply "Casey" <caseham2012 gmail.com> writes:
On Wednesday, 12 November 2014 at 19:29:26 UTC, Israel wrote:
 On Wednesday, 12 November 2014 at 04:56:40 UTC, Casey wrote:

 also, you came to the right place. PB is extremely paranoid and
 even more so about autohokey, so if you program your own native
 macro, its not very likely it will catch it.
I didn't see your replies at first... Thanks for your interest. If D isn't the right language, I can go with something else like C++ or python. It's just got to have something that can send low level chat messages, or emulate actual keyboard presses so that I Micro$oft makes it and I try to avoid their stuff as much as possible). I chose D simply because I've heard it's got a lot of potential and it's somewhat similar to C++, yet easyish to learn. I'm up for anything, but I figured that if I went with D or C++ I'd be jumping right into it, so that would give me the most experience. I thought this shouldn't be too hard to make, but I just can't find anything that does the job 'm looking for.
Nov 12 2014
parent reply "Israel" <tl12000 live.com> writes:
On Wednesday, 12 November 2014 at 19:43:49 UTC, Casey wrote:
 On Wednesday, 12 November 2014 at 19:29:26 UTC, Israel wrote:
 On Wednesday, 12 November 2014 at 04:56:40 UTC, Casey wrote:

 also, you came to the right place. PB is extremely paranoid and
 even more so about autohokey, so if you program your own native
 macro, its not very likely it will catch it.
I didn't see your replies at first... Thanks for your interest. If D isn't the right language, I can go with something else like C++ or python. It's just got to have something that can send low level chat messages, or emulate actual keyboard presses so that I won't have issues with other games. (/NOT/ stuff as much as possible). I chose D simply because I've heard it's got a lot of potential and it's somewhat similar to C++, yet easyish to learn. I'm up for anything, but I figured that if I went with D or C++ I'd be jumping right into it, so that would give me the most experience. I thought this shouldn't be too hard to make, but I just can't find anything that does the job 'm looking for.
Its not that D "isnt" the right language its just that it isnt "yet". There are few libraries that allow you to take control over the mouse and keyboard without too much hassle and reading through documentation. I did find this a couple days ago. http://code.dlang.org/packages/de_window It might be what you need but im not entirely sure if its input simulation is across all programs.
Nov 12 2014
parent reply "Casey" <caseham2012 gmail.com> writes:
On Wednesday, 12 November 2014 at 23:35:33 UTC, Israel wrote:
 On Wednesday, 12 November 2014 at 19:43:49 UTC, Casey wrote:
 On Wednesday, 12 November 2014 at 19:29:26 UTC, Israel wrote:
 On Wednesday, 12 November 2014 at 04:56:40 UTC, Casey wrote:

 also, you came to the right place. PB is extremely paranoid 
 and
 even more so about autohokey, so if you program your own 
 native
 macro, its not very likely it will catch it.
I didn't see your replies at first... Thanks for your interest. If D isn't the right language, I can go with something else like C++ or python. It's just got to have something that can send low level chat messages, or emulate actual keyboard presses so that I won't have issues with other games. (/NOT/ stuff as much as possible). I chose D simply because I've heard it's got a lot of potential and it's somewhat similar to C++, yet easyish to learn. I'm up for anything, but I figured that if I went with D or C++ I'd be jumping right into it, so that would give me the most experience. I thought this shouldn't be too hard to make, but I just can't find anything that does the job 'm looking for.
Its not that D "isnt" the right language its just that it isnt "yet". There are few libraries that allow you to take control over the mouse and keyboard without too much hassle and reading through documentation. I did find this a couple days ago. http://code.dlang.org/packages/de_window It might be what you need but im not entirely sure if its input simulation is across all programs.
I'll look into that, it seems as it might work. If D would be too hard to get working, what would you recommend? I would assume Ptyhon or C++ would be good choices, any chance you can recommend a forum for these or something? It's hard to find any documentation on what I am looking for. Thanks.
Nov 12 2014
parent reply "Israel" <tl12000 live.com> writes:
On Wednesday, 12 November 2014 at 23:40:09 UTC, Casey wrote:

 I'll look into that, it seems as it might work.  If D would be 
 too hard to get working, what would you recommend?  I would 
 assume Ptyhon or C++ would be good choices, any chance you can 
 recommend a forum for these or something?  It's hard to find 
 any documentation on what I am looking for.

 Thanks.
I tried to test out that de_window library but it doesnt work out of the box. The guy who created it though does post in this forum so maybe if he magically finds this thread he can help you and me out.
Nov 12 2014
parent reply "Casey" <caseham2012 gmail.com> writes:
On Thursday, 13 November 2014 at 01:35:28 UTC, Israel wrote:
 On Wednesday, 12 November 2014 at 23:40:09 UTC, Casey wrote:

 I'll look into that, it seems as it might work.  If D would be 
 too hard to get working, what would you recommend?  I would 
 assume Ptyhon or C++ would be good choices, any chance you can 
 recommend a forum for these or something?  It's hard to find 
 any documentation on what I am looking for.

 Thanks.
I tried to test out that de_window library but it doesnt work out of the box. The guy who created it though does post in this forum so maybe if he magically finds this thread he can help you and me out.
That would be nice. I'll see if there's a way to PM him about it. Do you have any other programming language recommendations in case this doesn't work out?
Nov 12 2014
parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 13/11/2014 2:37 p.m., Casey wrote:
 On Thursday, 13 November 2014 at 01:35:28 UTC, Israel wrote:
 On Wednesday, 12 November 2014 at 23:40:09 UTC, Casey wrote:

 I'll look into that, it seems as it might work.  If D would be too
 hard to get working, what would you recommend?  I would assume Ptyhon
 or C++ would be good choices, any chance you can recommend a forum
 for these or something?  It's hard to find any documentation on what
 I am looking for.

 Thanks.
I tried to test out that de_window library but it doesnt work out of the box. The guy who created it though does post in this forum so maybe if he magically finds this thread he can help you and me out.
That would be nice. I'll see if there's a way to PM him about it. Do you have any other programming language recommendations in case this doesn't work out?
Sorry that functionality of de_window is out of scope of it. So of course, it won't work for what you want, it just creates a window and a context cross platform with input for that window. The functionality you are wanting is possible against winapi and x11 fairly easily. Its just low level. Although X11 is a little easier as it can be done via a program on cli. Unfortunately c/c++ will help you as much as D will in these cases. If you run into trouble with those api's we can help you. But you will need help, these are topics that aren't recommended for a newbie. I'm not quite sure how to receive key presses from other windows. Maybe Mike Parker (aldracon) has some ideas.
Nov 12 2014
parent reply "Israel" <tl12000 live.com> writes:
On Thursday, 13 November 2014 at 02:00:11 UTC, Rikki Cattermole
wrote:
 On 13/11/2014 2:37 p.m., Casey wrote:
 On Thursday, 13 November 2014 at 01:35:28 UTC, Israel wrote:
 On Wednesday, 12 November 2014 at 23:40:09 UTC, Casey wrote:

 I'll look into that, it seems as it might work.  If D would 
 be too
 hard to get working, what would you recommend?  I would 
 assume Ptyhon
 or C++ would be good choices, any chance you can recommend a 
 forum
 for these or something?  It's hard to find any documentation 
 on what
 I am looking for.

 Thanks.
I tried to test out that de_window library but it doesnt work out of the box. The guy who created it though does post in this forum so maybe if he magically finds this thread he can help you and me out.
That would be nice. I'll see if there's a way to PM him about it. Do you have any other programming language recommendations in case this doesn't work out?
Sorry that functionality of de_window is out of scope of it. So of course, it won't work for what you want, it just creates a window and a context cross platform with input for that window. The functionality you are wanting is possible against winapi and x11 fairly easily. Its just low level. Although X11 is a little easier as it can be done via a program on cli. Unfortunately c/c++ will help you as much as D will in these cases. If you run into trouble with those api's we can help you. But you will need help, these are topics that aren't recommended for a newbie. I'm not quite sure how to receive key presses from other windows. Maybe Mike Parker (aldracon) has some ideas.
Do you have plans for making win32 bindings for the sendkeys? Im interested in this too. Id like to do it with D but ive only
Nov 12 2014
next sibling parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 13/11/2014 3:45 p.m., Israel wrote:
 On Thursday, 13 November 2014 at 02:00:11 UTC, Rikki Cattermole
 wrote:
 On 13/11/2014 2:37 p.m., Casey wrote:
 On Thursday, 13 November 2014 at 01:35:28 UTC, Israel wrote:
 On Wednesday, 12 November 2014 at 23:40:09 UTC, Casey wrote:

 I'll look into that, it seems as it might work.  If D would be too
 hard to get working, what would you recommend?  I would assume Ptyhon
 or C++ would be good choices, any chance you can recommend a forum
 for these or something?  It's hard to find any documentation on what
 I am looking for.

 Thanks.
I tried to test out that de_window library but it doesnt work out of the box. The guy who created it though does post in this forum so maybe if he magically finds this thread he can help you and me out.
That would be nice. I'll see if there's a way to PM him about it. Do you have any other programming language recommendations in case this doesn't work out?
Sorry that functionality of de_window is out of scope of it. So of course, it won't work for what you want, it just creates a window and a context cross platform with input for that window. The functionality you are wanting is possible against winapi and x11 fairly easily. Its just low level. Although X11 is a little easier as it can be done via a program on cli. Unfortunately c/c++ will help you as much as D will in these cases. If you run into trouble with those api's we can help you. But you will need help, these are topics that aren't recommended for a newbie. I'm not quite sure how to receive key presses from other windows. Maybe Mike Parker (aldracon) has some ideas.
Do you have plans for making win32 bindings for the sendkeys? Im interested in this too. Id like to do it with D but ive only
At this point in time, I have no plans for such a library. However if somebody wishes to implement under the devisualization org, I'm happy to help.
Nov 12 2014
parent reply "Casey" <caseham2012 gmail.com> writes:
On Thursday, 13 November 2014 at 02:58:02 UTC, Rikki Cattermole
wrote:
 On 13/11/2014 3:45 p.m., Israel wrote:
 On Thursday, 13 November 2014 at 02:00:11 UTC, Rikki Cattermole
 wrote:
 On 13/11/2014 2:37 p.m., Casey wrote:
 On Thursday, 13 November 2014 at 01:35:28 UTC, Israel wrote:
 On Wednesday, 12 November 2014 at 23:40:09 UTC, Casey wrote:

 I'll look into that, it seems as it might work.  If D 
 would be too
 hard to get working, what would you recommend?  I would 
 assume Ptyhon
 or C++ would be good choices, any chance you can recommend 
 a forum
 for these or something?  It's hard to find any 
 documentation on what
 I am looking for.

 Thanks.
I tried to test out that de_window library but it doesnt work out of the box. The guy who created it though does post in this forum so maybe if he magically finds this thread he can help you and me out.
That would be nice. I'll see if there's a way to PM him about it. Do you have any other programming language recommendations in case this doesn't work out?
Sorry that functionality of de_window is out of scope of it. So of course, it won't work for what you want, it just creates a window and a context cross platform with input for that window. The functionality you are wanting is possible against winapi and x11 fairly easily. Its just low level. Although X11 is a little easier as it can be done via a program on cli. Unfortunately c/c++ will help you as much as D will in these cases. If you run into trouble with those api's we can help you. But you will need help, these are topics that aren't recommended for a newbie. I'm not quite sure how to receive key presses from other windows. Maybe Mike Parker (aldracon) has some ideas.
Do you have plans for making win32 bindings for the sendkeys? Im interested in this too. Id like to do it with D but ive only InputSimulator.
At this point in time, I have no plans for such a library. However if somebody wishes to implement under the devisualization org, I'm happy to help.
It's great to have you two joining in on this thread! I'm excited to see how helpful you have all been, it's really encouraging me to learn more about this. Two of you guys have noted that D and C++ might not be the right languages for my purposes. If they won't work for it, could you make some other suggestions? I'd really prefer to make it work in D, but if it's not worth the trouble I'm more than happy to switch to something simpler. Thanks for your dedication all!
Nov 12 2014
parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 13/11/2014 7:18 p.m., Casey wrote:
 On Thursday, 13 November 2014 at 02:58:02 UTC, Rikki Cattermole
 wrote:
 On 13/11/2014 3:45 p.m., Israel wrote:
 On Thursday, 13 November 2014 at 02:00:11 UTC, Rikki Cattermole
 wrote:
 On 13/11/2014 2:37 p.m., Casey wrote:
 On Thursday, 13 November 2014 at 01:35:28 UTC, Israel wrote:
 On Wednesday, 12 November 2014 at 23:40:09 UTC, Casey wrote:

 I'll look into that, it seems as it might work.  If D would be too
 hard to get working, what would you recommend?  I would assume
 Ptyhon
 or C++ would be good choices, any chance you can recommend a forum
 for these or something?  It's hard to find any documentation on what
 I am looking for.

 Thanks.
I tried to test out that de_window library but it doesnt work out of the box. The guy who created it though does post in this forum so maybe if he magically finds this thread he can help you and me out.
That would be nice. I'll see if there's a way to PM him about it. Do you have any other programming language recommendations in case this doesn't work out?
Sorry that functionality of de_window is out of scope of it. So of course, it won't work for what you want, it just creates a window and a context cross platform with input for that window. The functionality you are wanting is possible against winapi and x11 fairly easily. Its just low level. Although X11 is a little easier as it can be done via a program on cli. Unfortunately c/c++ will help you as much as D will in these cases. If you run into trouble with those api's we can help you. But you will need help, these are topics that aren't recommended for a newbie. I'm not quite sure how to receive key presses from other windows. Maybe Mike Parker (aldracon) has some ideas.
Do you have plans for making win32 bindings for the sendkeys? Im interested in this too. Id like to do it with D but ive only
At this point in time, I have no plans for such a library. However if somebody wishes to implement under the devisualization org, I'm happy to help.
It's great to have you two joining in on this thread! I'm excited to see how helpful you have all been, it's really encouraging me to learn more about this. Two of you guys have noted that D and C++ might not be the right languages for my purposes. If they won't work for it, could you make some other suggestions? I'd really prefer to make it work in D, but if it's not worth the trouble I'm more than happy to switch to something simpler. Thanks for your dedication all!
D shouldn't be the limiting factor here. Neither would c/c++. At the end of the day you need to interface with the low level apis such as WinAPI. It might be directly with your own event loops ext. Or it could be indirectly via a wrapper library. I did find this [0]. I don't know what state its in for compilating/running ext. But it might give you a good starting point. [0] https://github.com/pythoneer/XInputSimulator
Nov 12 2014
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 13 November 2014 at 07:01:08 UTC, Rikki Cattermole 
wrote:
 I did find this [0]. I don't know what state its in for 
 compilating/running ext. But it might give you a good starting 
 point.

 [0] https://github.com/pythoneer/XInputSimulator
ooh there's some nice code for Linux in there! The Windows is only half implemented though... but this combined with my Windows code should get you enough example to write a cross-platform thing if you need it.
Nov 13 2014
parent reply "Casey" <caseham2012 gmail.com> writes:
On Thursday, 13 November 2014 at 16:04:43 UTC, Adam D. Ruppe 
wrote:
 On Thursday, 13 November 2014 at 07:01:08 UTC, Rikki Cattermole 
 wrote:
 I did find this [0]. I don't know what state its in for 
 compilating/running ext. But it might give you a good starting 
 point.

 [0] https://github.com/pythoneer/XInputSimulator
ooh there's some nice code for Linux in there! The Windows is only half implemented though... but this combined with my Windows code should get you enough example to write a cross-platform thing if you need it.
Thank you so much! I really appreciate this! But I have a few questions. 1) Which compiler should I use? I'm attempting to use the DM D comiler, but afaik it doesn't have a GUI and I can't make any sense of how to use it otherwise. I'll look up a tutorial on it if this is the one you recommend. If it's not the one you recommend, I'll give yours a try. 2) I can't figure out what the heck half of this code means. It seems that at the bottom you have what each of the hotkey buttons are, and I can see a few times where you referenced them. I can also see a efw listeners for the keybinds to be pressed, and then where you use the writeln command. Other than that, I can't tell what's going on. I feel like a noob, sorry that I don't understand this. 3) I'm sure that everything you have in there has a meaning, but it looks over complicated to me. Shouldn't it look something like this? [code] void main() { import std.stdio; import simpledisplay; import *Others that need to be imported*; if (*hotkey command here*) { then writeln ("We're losing Alpha!") return 0; } [/code] I know there's a /LOT/ more to it than that, but wouldn't that be the basics? I honestly don't know a whole lot about what you did, but at least I understand the basic concept of programming. I'm going to start looking up a few tutorials on compiling using the DM D compiler, let me know if you recommend a different one. Could you tell me which keys you used for the hotkey in your sample code? I can't figure it out, but my guess it alt + c? Not sure though. Thanks again, I am really impressed with you for actually writing the basic concept of it for me! I can diffidently use this for my building block of learning how to program better!
Nov 13 2014
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 13 November 2014 at 21:56:48 UTC, Casey wrote:
 1) Which compiler should I use?
I use the digital mars D. It is pretty easy from the command line, you put the code files in a directory then pop open a cmd prompt in that folder. If the compiler is installed, you should be able to just type "dmd your.d list.d of.d files.d" and it spits out an exe. The command for the program I gave is dmd hotkey.d simpledisplay.d color.d -L/SUBSYSTEM:WINDOWS:5.0: You would just copy/paste that into the command prompt from your folder. dmd is the name of the compiler, then the list of source files, and the last SUBSYSTEM bit is telling it to produce a Windows GUI program instead of a text based program.
 2) I can't figure out what the heck half of this code means.
yeah, Windows programming can be a bit weird even for experienced coders. Let me come back to you and explain each line in a future message.
 3) I'm sure that everything you have in there has a meaning, 
 but it looks over complicated to me.  Shouldn't it look 
 something like this?

 [code]
 void main() {
     import std.stdio;
     import simpledisplay;
     import *Others that need to be imported*;
     if (*hotkey command here*) {
     then writeln ("We're losing Alpha!")
     return 0;
 }
 [/code]
It potentially could look like that if the other underlying code was already written in a library or something, but you said you looked for an existing program to do what you want and couldn't find it, so here we're writing that underlying code! Any program that listens for multiple user events tends to be a bit more complicated than that though because you want to loop, waiting and reacting to several events, instead of always going forward. That's why my thing ends with window.eventLoop() instead of plain return - it keeps the window up until it is closed, reacting to various events. That line with handleNativeEvent sets up the reactions to those events. The operating system sends our window messages when things happen, and we run stuff in response to those messages. Since this program only cares about hotkeys, the only handled case is the WM_HOTKEY message, and in response to it, we send a string. All the other code surrounding those lines are just telling the library to do default behavior for the other messages (for example, close when the user clicks the X, or draw itself when it is minimized and restored). The rest of that file consists of two other parts: the sendString function, which creates the keyboard events to type out the message and forwards them to the operating system, and then the copy/pasted definitions of operating system functions (starting at the "import core.sys.windows.windows;" line) so we can call them. D doesn't come with all Windows functionality built in. It can use it all, but you often have to tell it what the functions' names and arguments are (or download a file that has this done already). That's all I'm doing in the second half of the program - that's copy/pasted info from Microsoft's documentation.
 Could you tell me which keys you used for the hotkey in your 
 sample code?  I can't figure it out, but my guess it alt + c?  
 Not sure though.
In my sample, the hotkey is set to F2. It is set on this line: if(!RegisterHotKey(window.impl.hwnd, hotkey_id, 0, VK_F2)) { The 0 in there means you don't have to hold ctrl, alt, or anything to trigger it. Then VK_F2 represents the F2 key (each key has its own "virtual key code" in Windows which you can find on a table on the Microsoft website. But the basic pattern is VK_ (for Virtual Key) then the name.
Nov 13 2014
prev sibling next sibling parent "Israel" <tl12000 live.com> writes:
On Thursday, 13 November 2014 at 21:56:48 UTC, Casey wrote:
 On Thursday, 13 November 2014 at 16:04:43 UTC, Adam D. Ruppe 
 wrote:
 On Thursday, 13 November 2014 at 07:01:08 UTC, Rikki 
 Cattermole wrote:
 I did find this [0]. I don't know what state its in for 
 compilating/running ext. But it might give you a good 
 starting point.

 [0] https://github.com/pythoneer/XInputSimulator
ooh there's some nice code for Linux in there! The Windows is only half implemented though... but this combined with my Windows code should get you enough example to write a cross-platform thing if you need it.
Thank you so much! I really appreciate this! But I have a few questions.
 2) I can't figure out what the heck half of this code means.  
 It seems that at the bottom you have what each of the hotkey 
 buttons are, and I can see a few times where you referenced 
 them.  I can also see a efw listeners for the keybinds to be 
 pressed, and then where you use the writeln command.  Other 
 than that, I can't tell what's going on.  I feel like a noob, 
 sorry that I don't understand this.

 3) I'm sure that everything you have in there has a meaning, 
 but it looks over complicated to me.  Shouldn't it look 
 something like this?

 [code]
 void main() {
     import std.stdio;
     import simpledisplay;
     import *Others that need to be imported*;
     if (*hotkey command here*) {
     then writeln ("We're losing Alpha!")
     return 0;
 }
 [/code]

 I know there's a /LOT/ more to it than that, but wouldn't that 
 be the basics?  I honestly don't know a whole lot about what 
 you did, but at least I understand the basic concept of 
 programming.

 I'm going to start looking up a few tutorials on compiling 
 using the DM D compiler, let me know if you recommend a 
 different one.

 Could you tell me which keys you used for the hotkey in your 
 sample code?  I can't figure it out, but my guess it alt + c?  
 Not sure though.

 Thanks again, I am really impressed with you for actually 
 writing the basic concept of it for me!  I can diffidently use 
 this for my building block of learning how to program better!
Well hes basically giving us the core of what we need to create a binding. Its like hes giving us a car engine and then we build the rest of it around that. Except im in the same boat, i cant figure out whats going on. Lol. Also, the only difference i see with the -L/SUSBSYSTEM:WINDOWS:5.0 switch is the the program runs with a command line program in the background. Thats fine i guess. Unless this does alot of other stuff in the background i dont understand.
 1) Which compiler should I use?  I'm attempting to use the DM D 
 comiler, but afaik it doesn't have a GUI and I can't make any 
 sense of how to use it otherwise.  I'll look up a tutorial on 
 it if this is the one you recommend.  If it's not the one you 
 recommend, I'll give yours a try.
The compiler has no GUI. After you install dmd it is then linked to your system so that you can use it anywhere. It runs as a background program but you can only run it from another command line. so Windows Key + R > cmd > click ok > navigate to the directory where the source code files are with "cd" and "dir" command line fucntions. Then type "dmd hotkey.d simpledisplay.d color.d" and the compiler will spit out a hotkey.exe executable.
Nov 13 2014
prev sibling parent reply "Casey" <caseham2012 gmail.com> writes:
On Thursday, 13 November 2014 at 21:56:48 UTC, Casey wrote:
 On Thursday, 13 November 2014 at 16:04:43 UTC, Adam D. Ruppe 
 wrote:
 On Thursday, 13 November 2014 at 07:01:08 UTC, Rikki 
 Cattermole wrote:
 I did find this [0]. I don't know what state its in for 
 compilating/running ext. But it might give you a good 
 starting point.

 [0] https://github.com/pythoneer/XInputSimulator
ooh there's some nice code for Linux in there! The Windows is only half implemented though... but this combined with my Windows code should get you enough example to write a cross-platform thing if you need it.
Thank you so much! I really appreciate this! But I have a few questions. 1) Which compiler should I use? I'm attempting to use the DM D comiler, but afaik it doesn't have a GUI and I can't make any sense of how to use it otherwise. I'll look up a tutorial on it if this is the one you recommend. If it's not the one you recommend, I'll give yours a try. 2) I can't figure out what the heck half of this code means. It seems that at the bottom you have what each of the hotkey buttons are, and I can see a few times where you referenced them. I can also see a efw listeners for the keybinds to be pressed, and then where you use the writeln command. Other than that, I can't tell what's going on. I feel like a noob, sorry that I don't understand this. 3) I'm sure that everything you have in there has a meaning, but it looks over complicated to me. Shouldn't it look something like this? [code] void main() { import std.stdio; import simpledisplay; import *Others that need to be imported*; if (*hotkey command here*) { then writeln ("We're losing Alpha!") return 0; } [/code] I know there's a /LOT/ more to it than that, but wouldn't that be the basics? I honestly don't know a whole lot about what you did, but at least I understand the basic concept of programming. I'm going to start looking up a few tutorials on compiling using the DM D compiler, let me know if you recommend a different one. Could you tell me which keys you used for the hotkey in your sample code? I can't figure it out, but my guess it alt + c? Not sure though. Thanks again, I am really impressed with you for actually writing the basic concept of it for me! I can diffidently use this for my building block of learning how to program better!
Ok so I've found out how to compile using the DM D compiler via terminal... I can't cd to my directory for whatever reason... so I'm running this: [code] dmd D:\Documents\Other\Hotkeys\D\Keybinds.d [/code] But it's spitting out errors left and right. Here's what I get: [code] C:\Users\Casey>dmd D:\Documents\Other\Hotkeys\D\Keybinds.d D:\Documents\Other\Hotkeys\D\Keybinds.d(11): Error: undefined identifier KEYEVEN TF_UNICODE D:\Documents\Other\Hotkeys\D\Keybinds.d(25): Error: module simpledisplay is in f ile 'simpledisplay.d' which cannot be read import path[0] = D:\Program Files (x86)\DM D Programming Language Compiler\D\dmd 2\windows\bin\..\..\src\phobos import path[1] = D:\Program Files (x86)\DM D Programming Language Compiler\D\dmd 2\windows\bin\..\..\src\druntime\import [/code] It's basically telling me I need the two files you mentioned that are on your Github. So I then went and got your two files, copied their stuff into their own folders, and tried to compile them. Here's what I got: [code] C:\Users\Casey>dmd D:\Documents\Other\Hotkeys\D\simpledisplay.d D:\Documents\Other\Hotkeys\D\simpledisplay.d(274): Error: module color is in fil e 'arsd\color.d' which cannot be read import path[0] = D:\Program Files (x86)\DM D Programming Language Compiler\D\dmd 2\windows\bin\..\..\src\phobos import path[1] = D:\Program Files (x86)\DM D Programming Language Compiler\D\dmd 2\windows\bin\..\..\src\druntime\import C:\Users\Casey>dmd D:\Documents\Other\Hotkeys\D\color.d OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 23: No Stack color.obj(color) Error 42: Symbol Undefined __fltused color.obj(color) Error 42: Symbol Undefined __d_arraybounds color.obj(color) Error 42: Symbol Undefined __memset80 color.obj(color) Error 42: Symbol Undefined __d_assert color.obj(color) Error 42: Symbol Undefined __d_arraycatT color.obj(color) Error 42: Symbol Undefined __d_throwc color.obj(color) Error 42: Symbol Undefined _D6object9Exception6__ctorMFNaNbNfAyaAyakC6object9Th rowableZC9Exception color.obj(color) Error 42: Symbol Undefined __d_newclass color.obj(color) Error 42: Symbol Undefined _D9Exception7__ClassZ color.obj(color) Error 42: Symbol Undefined _D12TypeInfo_Aya6__initZ color.obj(color) Error 42: Symbol Undefined __d_arrayappendcTX color.obj(color) Error 42: Symbol Undefined _D14TypeInfo_Array6__vtblZ color.obj(color) Error 42: Symbol Undefined __d_assert_msg color.obj(color) Error 42: Symbol Undefined _D9invariant12_d_invariantFC6ObjectZv color.obj(color) Error 42: Symbol Undefined _D11TypeInfo_Ah6__initZ color.obj(color) Error 42: Symbol Undefined __d_newarrayT color.obj(color) Error 42: Symbol Undefined __d_arraycast color.obj(color) Error 42: Symbol Undefined _D15TypeInfo_Struct6__vtblZ color.obj(color) Error 42: Symbol Undefined __d_arraycatnT color.obj(color) Error 42: Symbol Undefined __d_arrayappendcd color.obj(color) Error 42: Symbol Undefined _D11TypeInfo_Aa6__initZ color.obj(color) Error 42: Symbol Undefined _D6object6Object8toStringMFZAya color.obj(color) Error 42: Symbol Undefined _D6object6Object8opEqualsMFC6ObjectZb color.obj(color) Error 42: Symbol Undefined _D6Object7__ClassZ color.obj(color) Error 42: Symbol Undefined _D6object6Object6toHashMFNbNeZk color.obj(color) Error 42: Symbol Undefined _D14TypeInfo_Class6__vtblZ color.obj(color) Error 42: Symbol Undefined _D6object6Object5opCmpMFC6ObjectZi color.obj(color) Error 42: Symbol Undefined _D3std9algorithm12__ModuleInfoZ OPTLINK : Warning 134: No Start Address --- errorlevel 28 [/code] I'm not sure what this all means, but I'm sure I'm doing something wrong. It doesn't spit out any files, and from what I've seen it's supposed to spit out 3 new ones.
Nov 13 2014
next sibling parent reply "Israel" <tl12000 live.com> writes:
On Thursday, 13 November 2014 at 22:20:58 UTC, Casey wrote:
 On Thursday, 13 November 2014 at 21:56:48 UTC, Casey wrote:
 On Thursday, 13 November 2014 at 16:04:43 UTC, Adam D. Ruppe 
 wrote:
 On Thursday, 13 November 2014 at 07:01:08 UTC, Rikki 
 Cattermole wrote:
 I did find this [0]. I don't know what state its in for 
 compilating/running ext. But it might give you a good 
 starting point.

 [0] https://github.com/pythoneer/XInputSimulator
ooh there's some nice code for Linux in there! The Windows is only half implemented though... but this combined with my Windows code should get you enough example to write a cross-platform thing if you need it.
Thank you so much! I really appreciate this! But I have a few questions. 1) Which compiler should I use? I'm attempting to use the DM D comiler, but afaik it doesn't have a GUI and I can't make any sense of how to use it otherwise. I'll look up a tutorial on it if this is the one you recommend. If it's not the one you recommend, I'll give yours a try. 2) I can't figure out what the heck half of this code means. It seems that at the bottom you have what each of the hotkey buttons are, and I can see a few times where you referenced them. I can also see a efw listeners for the keybinds to be pressed, and then where you use the writeln command. Other than that, I can't tell what's going on. I feel like a noob, sorry that I don't understand this. 3) I'm sure that everything you have in there has a meaning, but it looks over complicated to me. Shouldn't it look something like this? [code] void main() { import std.stdio; import simpledisplay; import *Others that need to be imported*; if (*hotkey command here*) { then writeln ("We're losing Alpha!") return 0; } [/code] I know there's a /LOT/ more to it than that, but wouldn't that be the basics? I honestly don't know a whole lot about what you did, but at least I understand the basic concept of programming. I'm going to start looking up a few tutorials on compiling using the DM D compiler, let me know if you recommend a different one. Could you tell me which keys you used for the hotkey in your sample code? I can't figure it out, but my guess it alt + c? Not sure though. Thanks again, I am really impressed with you for actually writing the basic concept of it for me! I can diffidently use this for my building block of learning how to program better!
Ok so I've found out how to compile using the DM D compiler via terminal... I can't cd to my directory for whatever reason... so I'm running this: [code] dmd D:\Documents\Other\Hotkeys\D\Keybinds.d [/code] But it's spitting out errors left and right. Here's what I get: [code] C:\Users\Casey>dmd D:\Documents\Other\Hotkeys\D\Keybinds.d D:\Documents\Other\Hotkeys\D\Keybinds.d(11): Error: undefined identifier KEYEVEN TF_UNICODE D:\Documents\Other\Hotkeys\D\Keybinds.d(25): Error: module simpledisplay is in f ile 'simpledisplay.d' which cannot be read import path[0] = D:\Program Files (x86)\DM D Programming Language Compiler\D\dmd 2\windows\bin\..\..\src\phobos import path[1] = D:\Program Files (x86)\DM D Programming Language Compiler\D\dmd 2\windows\bin\..\..\src\druntime\import [/code] It's basically telling me I need the two files you mentioned that are on your Github. So I then went and got your two files, copied their stuff into their own folders, and tried to compile them. Here's what I got: [code] C:\Users\Casey>dmd D:\Documents\Other\Hotkeys\D\simpledisplay.d D:\Documents\Other\Hotkeys\D\simpledisplay.d(274): Error: module color is in fil e 'arsd\color.d' which cannot be read import path[0] = D:\Program Files (x86)\DM D Programming Language Compiler\D\dmd 2\windows\bin\..\..\src\phobos import path[1] = D:\Program Files (x86)\DM D Programming Language Compiler\D\dmd 2\windows\bin\..\..\src\druntime\import C:\Users\Casey>dmd D:\Documents\Other\Hotkeys\D\color.d OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 23: No Stack color.obj(color) Error 42: Symbol Undefined __fltused color.obj(color) Error 42: Symbol Undefined __d_arraybounds color.obj(color) Error 42: Symbol Undefined __memset80 color.obj(color) Error 42: Symbol Undefined __d_assert color.obj(color) Error 42: Symbol Undefined __d_arraycatT color.obj(color) Error 42: Symbol Undefined __d_throwc color.obj(color) Error 42: Symbol Undefined _D6object9Exception6__ctorMFNaNbNfAyaAyakC6object9Th rowableZC9Exception color.obj(color) Error 42: Symbol Undefined __d_newclass color.obj(color) Error 42: Symbol Undefined _D9Exception7__ClassZ color.obj(color) Error 42: Symbol Undefined _D12TypeInfo_Aya6__initZ color.obj(color) Error 42: Symbol Undefined __d_arrayappendcTX color.obj(color) Error 42: Symbol Undefined _D14TypeInfo_Array6__vtblZ color.obj(color) Error 42: Symbol Undefined __d_assert_msg color.obj(color) Error 42: Symbol Undefined _D9invariant12_d_invariantFC6ObjectZv color.obj(color) Error 42: Symbol Undefined _D11TypeInfo_Ah6__initZ color.obj(color) Error 42: Symbol Undefined __d_newarrayT color.obj(color) Error 42: Symbol Undefined __d_arraycast color.obj(color) Error 42: Symbol Undefined _D15TypeInfo_Struct6__vtblZ color.obj(color) Error 42: Symbol Undefined __d_arraycatnT color.obj(color) Error 42: Symbol Undefined __d_arrayappendcd color.obj(color) Error 42: Symbol Undefined _D11TypeInfo_Aa6__initZ color.obj(color) Error 42: Symbol Undefined _D6object6Object8toStringMFZAya color.obj(color) Error 42: Symbol Undefined _D6object6Object8opEqualsMFC6ObjectZb color.obj(color) Error 42: Symbol Undefined _D6Object7__ClassZ color.obj(color) Error 42: Symbol Undefined _D6object6Object6toHashMFNbNeZk color.obj(color) Error 42: Symbol Undefined _D14TypeInfo_Class6__vtblZ color.obj(color) Error 42: Symbol Undefined _D6object6Object5opCmpMFC6ObjectZi color.obj(color) Error 42: Symbol Undefined _D3std9algorithm12__ModuleInfoZ OPTLINK : Warning 134: No Start Address --- errorlevel 28 [/code] I'm not sure what this all means, but I'm sure I'm doing something wrong. It doesn't spit out any files, and from what I've seen it's supposed to spit out 3 new ones.
All 3 files need to be in the same folder. (simpledisplay.d, color.d, hotkeys.d) When you call dmd youre only calling 1 file which was hotkeys.d. You need to specify the other 2 like this.
dmd "D:\Documents\Other\Hotkeys\D\simpledisplay.d" 
"D:\Documents\Other\Hotkeys\D\color.d" 
"D:\Documents\Other\Hotkeys\D\hotkeys.d"
Nov 13 2014
parent reply "Casey" <caseham2012 gmail.com> writes:
On Thursday, 13 November 2014 at 22:28:43 UTC, Israel wrote:
 On Thursday, 13 November 2014 at 22:20:58 UTC, Casey wrote:
 On Thursday, 13 November 2014 at 21:56:48 UTC, Casey wrote:
 On Thursday, 13 November 2014 at 16:04:43 UTC, Adam D. Ruppe 
 wrote:
 On Thursday, 13 November 2014 at 07:01:08 UTC, Rikki 
 Cattermole wrote:
 I did find this [0]. I don't know what state its in for 
 compilating/running ext. But it might give you a good 
 starting point.

 [0] https://github.com/pythoneer/XInputSimulator
ooh there's some nice code for Linux in there! The Windows is only half implemented though... but this combined with my Windows code should get you enough example to write a cross-platform thing if you need it.
Thank you so much! I really appreciate this! But I have a few questions. 1) Which compiler should I use? I'm attempting to use the DM D comiler, but afaik it doesn't have a GUI and I can't make any sense of how to use it otherwise. I'll look up a tutorial on it if this is the one you recommend. If it's not the one you recommend, I'll give yours a try. 2) I can't figure out what the heck half of this code means. It seems that at the bottom you have what each of the hotkey buttons are, and I can see a few times where you referenced them. I can also see a efw listeners for the keybinds to be pressed, and then where you use the writeln command. Other than that, I can't tell what's going on. I feel like a noob, sorry that I don't understand this. 3) I'm sure that everything you have in there has a meaning, but it looks over complicated to me. Shouldn't it look something like this? [code] void main() { import std.stdio; import simpledisplay; import *Others that need to be imported*; if (*hotkey command here*) { then writeln ("We're losing Alpha!") return 0; } [/code] I know there's a /LOT/ more to it than that, but wouldn't that be the basics? I honestly don't know a whole lot about what you did, but at least I understand the basic concept of programming. I'm going to start looking up a few tutorials on compiling using the DM D compiler, let me know if you recommend a different one. Could you tell me which keys you used for the hotkey in your sample code? I can't figure it out, but my guess it alt + c? Not sure though. Thanks again, I am really impressed with you for actually writing the basic concept of it for me! I can diffidently use this for my building block of learning how to program better!
Ok so I've found out how to compile using the DM D compiler via terminal... I can't cd to my directory for whatever reason... so I'm running this: [code] dmd D:\Documents\Other\Hotkeys\D\Keybinds.d [/code] But it's spitting out errors left and right. Here's what I get: [code] C:\Users\Casey>dmd D:\Documents\Other\Hotkeys\D\Keybinds.d D:\Documents\Other\Hotkeys\D\Keybinds.d(11): Error: undefined identifier KEYEVEN TF_UNICODE D:\Documents\Other\Hotkeys\D\Keybinds.d(25): Error: module simpledisplay is in f ile 'simpledisplay.d' which cannot be read import path[0] = D:\Program Files (x86)\DM D Programming Language Compiler\D\dmd 2\windows\bin\..\..\src\phobos import path[1] = D:\Program Files (x86)\DM D Programming Language Compiler\D\dmd 2\windows\bin\..\..\src\druntime\import [/code] It's basically telling me I need the two files you mentioned that are on your Github. So I then went and got your two files, copied their stuff into their own folders, and tried to compile them. Here's what I got: [code] C:\Users\Casey>dmd D:\Documents\Other\Hotkeys\D\simpledisplay.d D:\Documents\Other\Hotkeys\D\simpledisplay.d(274): Error: module color is in fil e 'arsd\color.d' which cannot be read import path[0] = D:\Program Files (x86)\DM D Programming Language Compiler\D\dmd 2\windows\bin\..\..\src\phobos import path[1] = D:\Program Files (x86)\DM D Programming Language Compiler\D\dmd 2\windows\bin\..\..\src\druntime\import C:\Users\Casey>dmd D:\Documents\Other\Hotkeys\D\color.d OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html OPTLINK : Warning 23: No Stack color.obj(color) Error 42: Symbol Undefined __fltused color.obj(color) Error 42: Symbol Undefined __d_arraybounds color.obj(color) Error 42: Symbol Undefined __memset80 color.obj(color) Error 42: Symbol Undefined __d_assert color.obj(color) Error 42: Symbol Undefined __d_arraycatT color.obj(color) Error 42: Symbol Undefined __d_throwc color.obj(color) Error 42: Symbol Undefined _D6object9Exception6__ctorMFNaNbNfAyaAyakC6object9Th rowableZC9Exception color.obj(color) Error 42: Symbol Undefined __d_newclass color.obj(color) Error 42: Symbol Undefined _D9Exception7__ClassZ color.obj(color) Error 42: Symbol Undefined _D12TypeInfo_Aya6__initZ color.obj(color) Error 42: Symbol Undefined __d_arrayappendcTX color.obj(color) Error 42: Symbol Undefined _D14TypeInfo_Array6__vtblZ color.obj(color) Error 42: Symbol Undefined __d_assert_msg color.obj(color) Error 42: Symbol Undefined _D9invariant12_d_invariantFC6ObjectZv color.obj(color) Error 42: Symbol Undefined _D11TypeInfo_Ah6__initZ color.obj(color) Error 42: Symbol Undefined __d_newarrayT color.obj(color) Error 42: Symbol Undefined __d_arraycast color.obj(color) Error 42: Symbol Undefined _D15TypeInfo_Struct6__vtblZ color.obj(color) Error 42: Symbol Undefined __d_arraycatnT color.obj(color) Error 42: Symbol Undefined __d_arrayappendcd color.obj(color) Error 42: Symbol Undefined _D11TypeInfo_Aa6__initZ color.obj(color) Error 42: Symbol Undefined _D6object6Object8toStringMFZAya color.obj(color) Error 42: Symbol Undefined _D6object6Object8opEqualsMFC6ObjectZb color.obj(color) Error 42: Symbol Undefined _D6Object7__ClassZ color.obj(color) Error 42: Symbol Undefined _D6object6Object6toHashMFNbNeZk color.obj(color) Error 42: Symbol Undefined _D14TypeInfo_Class6__vtblZ color.obj(color) Error 42: Symbol Undefined _D6object6Object5opCmpMFC6ObjectZi color.obj(color) Error 42: Symbol Undefined _D3std9algorithm12__ModuleInfoZ OPTLINK : Warning 134: No Start Address --- errorlevel 28 [/code] I'm not sure what this all means, but I'm sure I'm doing something wrong. It doesn't spit out any files, and from what I've seen it's supposed to spit out 3 new ones.
All 3 files need to be in the same folder. (simpledisplay.d, color.d, hotkeys.d) When you call dmd youre only calling 1 file which was hotkeys.d. You need to specify the other 2 like this.
dmd "D:\Documents\Other\Hotkeys\D\simpledisplay.d" 
"D:\Documents\Other\Hotkeys\D\color.d" 
"D:\Documents\Other\Hotkeys\D\hotkeys.d"
Ok so I ran that, and it sends me the error that Windows can't open this type of file, and asks me if I want to look for a new program to run it or select one from the installed list. I told it to open it with the dmd.exe compiler, and now it apparently just made a new file called "dmd" with the type of "File". It's 0KB in size, so that didn't work. The other two commands tell me that the syntax is wrong, so idk.
Nov 13 2014
parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 13 November 2014 at 22:35:56 UTC, Casey wrote:
 Ok so I ran that, and it sends me the error that Windows can't
Once you cd to the folder, it becomes pretty simple, just do: dmd hotkey.d simpledisplay.d color.d all three files on one line - that's important because otherwise it won't find them all together and will try to do something else. It should spit out hotkey.exe after that.
Nov 13 2014
next sibling parent "Israel" <tl12000 live.com> writes:
Maybe a screenshot might help?

https://ooymza.dm2301.livefilestore.com/y2mt_9Z73WLi-1zso3LEjdCiC1x-GQzpjlaaftIFJ2Q0cHX2jd9vvwmVldHj1qRROER9IjiA1WwTzln5zveB9ZKZMrb1eeYNUgbzWQJlztqFAvQroAYm0k7_M4fuU3-XzAL/DMD.png
Nov 13 2014
prev sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
I just reorganized the code adding that stuff to simpledisplay.d. 
I think you should still understand the implementation code so 
you can customize it, but the main thing should look simpler now:

// same command to compile as before:
// dmd hotkey.d simpledisplay.d color.d -L/SUBSYSTEM:WINDOWS:5.0

void main() {
	import core.sys.windows.windows;
	import simpledisplay;

	auto window = new SimpleWindow(100, 50, "Hotkey");

	window.registerHotKey(0, VK_F2, {
		sendSyntheticInput("Hello");
	});
	window.registerHotKey(0, VK_F4, {
		sendSyntheticInput(", world!\n");
	});

	window.eventLoop(0);
}

Update simpledisplay.d by downloading the new file from github
https://github.com/adamdruppe/arsd/blob/master/simpledisplay.d


The new function works the same way as the old: modifiers, then 
virtual key code. The difference is the handler is put on the 
same line (I also renamed sendString to sendSyntheticInput to fit 
in simpledisplay.d).


Heck, I could even make this an exe with a little text area 
inside the window to set the listener script and a GUI to select 
the keys if I spent another hour or two on it...

but meh, see how far you can get now, playing with it a while 
will help you learn too.
Nov 13 2014
parent reply "Casey" <caseham2012 gmail.com> writes:
All on the same line... That makes a lot more sense.  Sorry, I 
probably just didn't understand what you meant.  I'll do that now 
and see if I can't get this working.  Then I'll try to get it 
working in a game.  I think I'll have to come up with something 
to add a delay in between the chat key down and chat key up, as 
without that, it didn't work with AHK.

I have this error now:

D:\Documents\Other\Hotkeys\D>dmd Keybinds.d simpledisplay.d 
color.d
Keybinds.d(11): Error: undefined identifier KEYEVENTF_UNICODE

Not sure what to do at this point.
Nov 13 2014
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 13 November 2014 at 23:54:13 UTC, Casey wrote:
 D:\Documents\Other\Hotkeys\D>dmd Keybinds.d simpledisplay.d 
 color.d
 Keybinds.d(11): Error: undefined identifier KEYEVENTF_UNICODE
That should have been on the last line of the file, maybe it just got cut off in the copying process. you can add it back: enum KEYEVENTF_UNICODE = 0x4; to the bottom.
Nov 13 2014
prev sibling parent reply "Casey" <caseham2012 gmail.com> writes:
On Thursday, 13 November 2014 at 23:54:13 UTC, Casey wrote:
 All on the same line... That makes a lot more sense.  Sorry, I 
 probably just didn't understand what you meant.  I'll do that 
 now and see if I can't get this working.  Then I'll try to get 
 it working in a game.  I think I'll have to come up with 
 something to add a delay in between the chat key down and chat 
 key up, as without that, it didn't work with AHK.

 I have this error now:

 D:\Documents\Other\Hotkeys\D>dmd Keybinds.d simpledisplay.d 
 color.d
 Keybinds.d(11): Error: undefined identifier KEYEVENTF_UNICODE

 Not sure what to do at this point.
Now I feel like a real idiot. It's telling me there's an error on line 11 if I'm not mistaken. I'm going to see if I edited your code by mistake and report back here. Yep, it didn't give an error this time around. However when I run the .exe I get your popup window and a blank terminal. Pressing all the F keys does nothing.
Nov 13 2014
parent reply "Casey" <caseham2012 gmail.com> writes:
On Thursday, 13 November 2014 at 23:59:59 UTC, Casey wrote:
 On Thursday, 13 November 2014 at 23:54:13 UTC, Casey wrote:
 All on the same line... That makes a lot more sense.  Sorry, I 
 probably just didn't understand what you meant.  I'll do that 
 now and see if I can't get this working.  Then I'll try to get 
 it working in a game.  I think I'll have to come up with 
 something to add a delay in between the chat key down and chat 
 key up, as without that, it didn't work with AHK.

 I have this error now:

 D:\Documents\Other\Hotkeys\D>dmd Keybinds.d simpledisplay.d 
 color.d
 Keybinds.d(11): Error: undefined identifier KEYEVENTF_UNICODE

 Not sure what to do at this point.
Now I feel like a real idiot. It's telling me there's an error on line 11 if I'm not mistaken. I'm going to see if I edited your code by mistake and report back here. Yep, it didn't give an error this time around. However when I run the .exe I get your popup window and a blank terminal. Pressing all the F keys does nothing.
Nevermind, working now.
Nov 13 2014
parent reply "Casey" <caseham2012 gmail.com> writes:
Well, I edited the code to add the chat button, and as I feared 
it didn't recignise it in game.  However, if I manually press the 
chat button it'll work fine, so all I need to do is add that 
delay in, then fine tune it to add all of the different messages 
I need now.

1)What part of this do I need to keep when adding the second 
hotkey?  Include an example if possible.  I find it hard to 
understand what is necessary to repeat and what I can just 
include once.

2)All I need to do at the moment to enable this to work is to add 
a ~1ms delay from the time the chat key is pressed down, and when 
it is pressed up.  Then it /should/ funtion in game properly.

3)It's a personal preference of mine to not have the chat window 
pop up like it does, nor the terminal popup.  This is a minor 
request, so I don't need it immediately.  Is there any way to 
make those disappear?

4)I'd like the first hotkey to be 0 + 1 on the numpad.  Numlock 
is always enabled on my keyboard, so I can't use arrows or 
anything like that.  The second set of hotkeys would be Ctrl + 
Del/End/PgDn/Insert/Home/PgUp, each one sending a different 
message.

5)Is there any way to pause the commands?  I have one hotkey set 
to Ctrl + Delete, and it gets really annoying when I try to 
Delete a full word but instead I send a chat message.  I think 
that I could activate and pause it with another hotkey, something 
like ctrl + numpad 0.  That should be something I'd never press.

I'm going to see if I can't figure everything above out on my 
own.  Maybe I'll start to learn it a bit more.  I'm also assuming 
I'll need another package to be imported if I am to add that 
delay, but it might already be in one of these.

Thanks so much everyone for your help.  It really means a lot to 
me.
Nov 13 2014
next sibling parent "Casey" <caseham2012 gmail.com> writes:
Aha!  I found a sleep command.

On this page here:

http://forum.dlang.org/thread/diuepu$2ebg$1 digitaldaemon.com

Looks like I'd do something like this

[code]
import std.c.time
msleep(1)
[/code]

Now I'm looking into if there's a way to send a key down, and 
then up.  I don't think this will be too easy to find though.
Nov 13 2014
prev sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Friday, 14 November 2014 at 02:08:22 UTC, Casey wrote:
 Well, I edited the code to add the chat button, and as I feared 
 it didn't recignise it in game.  However, if I manually press 
 the chat button it'll work fine
What exactly happened there?
 1)What part of this do I need to keep when adding the second 
 hotkey?  Include an example if possible.  I find it hard to 
 understand what is necessary to repeat and what I can just 
 include once.
The RegisterHotKey function will need to be called again with a new ID. Then, the WM_HOTKEY message will have to handle the other hotkey id too. You can copy and paste every instance of hotkey_id to make a hotkey2_id in a pinch. I know there's a lot of concepts behind the MSDN pages that aren't all newbie friendly (well, actually, there are pages on it to explain the concepts too, in the References part at the bottom of each page. You'll be in for many hours of reading though, it took me weeks to get going beyond copy/paste and it was /years/ before I knew all the concepts, but gotta start somewhere). Anyway, take a look at the pages to better understand what the code is doing - the concepts will make sense too once you see enough of it and in the mean time, it can help to explain the pieces in isolation. http://msdn.microsoft.com/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ms646279%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/ms646310%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/ms646271%28v=vs.85%29.aspx This is all Windows specific, of course, but the concepts apply to a lot of systems - if you can write Win32 code, you can do a lot of stuff.
 2)All I need to do at the moment to enable this to work is to 
 add a ~1ms delay from the time the chat key is pressed down, 
 and when it is pressed up.  Then it /should/ funtion in game 
 properly.
The easiest way would be to split up the part that does SendInput into two parts - notice how in the code, there were separate events for pressed and released. You'd need to split that up into two separate calls to SendInput with some kind of sleep in between. There's also a timestamp thing mentioned in the MSDN docs which might work but I'm not sure that would actually work.
 3)It's a personal preference of mine to not have the chat 
 window pop up like it does, nor the terminal popup.  This is a 
 minor request, so I don't need it immediately.  Is there any 
 way to make those disappear?
The terminal won't appear if you use the -L SUBSYSTEM thing from a previous post on the compile command at the end of the lit of files. The window itself could be hidden with the ShowWindow system function, but then you'd have to consider: how will you close the program when you don't want the hotkeys registered anymore? Having a visible window makes that easy. http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548%28v=vs.85%29.aspx The hwnd ShowWindow needs is available through window.impl.hwnd, so like ShowWindow(window.impl.hwnd, SW_HIDE); i should add this to simpledisplay.d too...
 4)I'd like the first hotkey to be 0 + 1 on the numpad.  Numlock 
 is always enabled on my keyboard, so I can't use arrows or 
 anything like that.  The second set of hotkeys would be Ctrl + 
 Del/End/PgDn/Insert/Home/PgUp, each one sending a different 
 message.
The Virtual Keys thing is the answer here. Search for virtual key codes on MSDN and you'll find this http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx Then search that page for "Numeric keypad 0 key" and you'll find the VK_NUMPAD0 name and number.
 5)Is there any way to pause the commands?  I have one hotkey 
 set to Ctrl + Delete, and it gets really annoying when I try to 
 Delete a full word but instead I send a chat message.  I think 
 that I could activate and pause it with another hotkey, 
 something like ctrl + numpad 0.  That should be something I'd 
 never press.
This is pretty straightforward: you can use an if clause with a variable in the WM_HOTKEY message to skip processing. Or, you could use UnregisterHotKey, passing the hwnd from the window and the ID number to turn it off entirely, then RegisterHotKey again later to turn it back on.
 I'm going to see if I can't figure everything above out on my 
 own.  Maybe I'll start to learn it a bit more.  I'm also 
 assuming I'll need another package to be imported if I am to 
 add that delay, but it might already be in one of these.
core.thread is one you can import, that gives you Thread.sleep http://dlang.org/phobos/core_thread.html#sleep This isn't the way you'd do this in a real program - it is usually a bad idea to sleep the thread responsible for handling window messages because then it can become unresponsive, but as long as you only sleep for a few milliseconds at a time it shouldn't be an issue.
Nov 13 2014
parent "Casey" <caseham2012 gmail.com> writes:
On Friday, 14 November 2014 at 03:51:17 UTC, Adam D. Ruppe wrote:
 On Friday, 14 November 2014 at 02:08:22 UTC, Casey wrote:
 Well, I edited the code to add the chat button, and as I 
 feared it didn't recignise it in game.  However, if I manually 
 press the chat button it'll work fine
What exactly happened there?
 1)What part of this do I need to keep when adding the second 
 hotkey?  Include an example if possible.  I find it hard to 
 understand what is necessary to repeat and what I can just 
 include once.
The RegisterHotKey function will need to be called again with a new ID. Then, the WM_HOTKEY message will have to handle the other hotkey id too. You can copy and paste every instance of hotkey_id to make a hotkey2_id in a pinch. I know there's a lot of concepts behind the MSDN pages that aren't all newbie friendly (well, actually, there are pages on it to explain the concepts too, in the References part at the bottom of each page. You'll be in for many hours of reading though, it took me weeks to get going beyond copy/paste and it was /years/ before I knew all the concepts, but gotta start somewhere). Anyway, take a look at the pages to better understand what the code is doing - the concepts will make sense too once you see enough of it and in the mean time, it can help to explain the pieces in isolation. http://msdn.microsoft.com/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ms646279%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/ms646310%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/ms646271%28v=vs.85%29.aspx This is all Windows specific, of course, but the concepts apply to a lot of systems - if you can write Win32 code, you can do a lot of stuff.
 2)All I need to do at the moment to enable this to work is to 
 add a ~1ms delay from the time the chat key is pressed down, 
 and when it is pressed up.  Then it /should/ funtion in game 
 properly.
The easiest way would be to split up the part that does SendInput into two parts - notice how in the code, there were separate events for pressed and released. You'd need to split that up into two separate calls to SendInput with some kind of sleep in between. There's also a timestamp thing mentioned in the MSDN docs which might work but I'm not sure that would actually work.
 3)It's a personal preference of mine to not have the chat 
 window pop up like it does, nor the terminal popup.  This is a 
 minor request, so I don't need it immediately.  Is there any 
 way to make those disappear?
The terminal won't appear if you use the -L SUBSYSTEM thing from a previous post on the compile command at the end of the lit of files. The window itself could be hidden with the ShowWindow system function, but then you'd have to consider: how will you close the program when you don't want the hotkeys registered anymore? Having a visible window makes that easy. http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548%28v=vs.85%29.aspx The hwnd ShowWindow needs is available through window.impl.hwnd, so like ShowWindow(window.impl.hwnd, SW_HIDE); i should add this to simpledisplay.d too...
 4)I'd like the first hotkey to be 0 + 1 on the numpad.  
 Numlock is always enabled on my keyboard, so I can't use 
 arrows or anything like that.  The second set of hotkeys would 
 be Ctrl + Del/End/PgDn/Insert/Home/PgUp, each one sending a 
 different message.
The Virtual Keys thing is the answer here. Search for virtual key codes on MSDN and you'll find this http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx Then search that page for "Numeric keypad 0 key" and you'll find the VK_NUMPAD0 name and number.
 5)Is there any way to pause the commands?  I have one hotkey 
 set to Ctrl + Delete, and it gets really annoying when I try 
 to Delete a full word but instead I send a chat message.  I 
 think that I could activate and pause it with another hotkey, 
 something like ctrl + numpad 0.  That should be something I'd 
 never press.
This is pretty straightforward: you can use an if clause with a variable in the WM_HOTKEY message to skip processing. Or, you could use UnregisterHotKey, passing the hwnd from the window and the ID number to turn it off entirely, then RegisterHotKey again later to turn it back on.
 I'm going to see if I can't figure everything above out on my 
 own.  Maybe I'll start to learn it a bit more.  I'm also 
 assuming I'll need another package to be imported if I am to 
 add that delay, but it might already be in one of these.
core.thread is one you can import, that gives you Thread.sleep http://dlang.org/phobos/core_thread.html#sleep This isn't the way you'd do this in a real program - it is usually a bad idea to sleep the thread responsible for handling window messages because then it can become unresponsive, but as long as you only sleep for a few milliseconds at a time it shouldn't be an issue.
I do see your point about closing it, that is something to consider. However, if I could minimize it to a try that would be better. I can't figure out how to separate the key press down and key press up, but if I can figure that out I should be good to go. I'll give everything mentioned here a try out tomorrow evening sometime. Thanks so much!
Nov 13 2014
prev sibling parent "Casey" <caseham2012 gmail.com> writes:
I also just now got it to CD to the right directory.  I had a 
suspicion it was having an issue with the second drive, and it 
was.  Just had to type D: and it did the rest.
Nov 13 2014
prev sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Thursday, 13 November 2014 at 02:45:34 UTC, Israel wrote:
 Do you have plans for making win32 bindings for the sendkeys?
I'm pretty sure it just calls this function: http://msdn.microsoft.com/en-us/library/ms646310%28v=vs.85%29.aspx with appropriate input prepared. As to listen to keyboard input, I'm again pretty sure you just need to call this function: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx It needs a window and event loop to receive the message, but that's not rocket science either, my simpledisplay.d can do it or it isn't really hard to just do with the low level calls. I'm not sure about how to do it on X11 off the top of my head, but there's functions to add event messages and listen to input from multiple windows, or you could open the /dev/input for the keyboard too if root. I've looked into this before and found a few options, but don't remember the details right now. I don't want to give a sample program without testing it, and I'm on my Linux box right now, but if you don't have something by tomorrow I'll play for a while when i'm on my laptop.
Nov 12 2014
prev sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
I wrote a program to get you started. It needs simpledisplay.d 
and color.d from my github https://github.com/adamdruppe/arsd

Just download those two files and put them in your folder along 
with the following contents as hotkey.d and you should get 
started.

I tested on Windows 7 to hotkey type some stuff into a Notepad 
window.

Here's the code:



// compile: dmd hotkey.d simpledisplay.d color.d 
-L/SUBSYSTEM:WINDOWS:5.0

// helper function to send a string. Call with like "hello!"w -- 
notice
// the w at the end of the string literal.
void sendString(wstring s) {
	INPUT[] inputs;
	inputs.reserve(s.length * 2);

	foreach(wchar c; s) {
                 // the basic pattern here is to send a unicode key
                 // pressed then released
		INPUT input;
		input.type = INPUT_KEYBOARD;
		input.ki.wScan = c;
		input.ki.dwFlags = KEYEVENTF_UNICODE;
		inputs ~= input;

		input.ki.dwFlags |= KEYEVENTF_KEYUP; // released...
		inputs ~= input;
	}

         // then send it to the operating system
	if(SendInput(inputs.length, inputs.ptr, INPUT.sizeof) != 
inputs.length) {
		import std.stdio;
		writeln("SendInput failed");
	}
}

// the SendInput function can also send other keys, see the MSDN 
link
// I gave in my last email for details.

void main() {
         // uses my simpledisplay.d to pop up a quick window
	import simpledisplay;

	enum hotkey_id = 1; // arbitrary unique ID for the program

	auto window = new SimpleWindow(100, 50);
	window.handleNativeEvent = delegate int(HWND hwnd, UINT msg, 
WPARAM wParam, LPARAM lParam) {
		if(hwnd !is window.impl.hwnd)
			return 1; // we don't care...
		switch(msg) {
			// 
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646279%28v=vs.85%29.aspx
			case WM_HOTKEY:
				if(wParam == hotkey_id) {
                                      // *** This is what happens 
when it is pressed!!! ***
					// MessageBoxA(window.impl.hwnd, "Hotkey", "Pressed!", 
MB_OK);
					sendString("Hey, it worked!"w);
					return 0;
				}
			goto default;
			default: return 1; // not handled, pass it on
		}
		return 0;
	};

	string message = "Hotkey ready";

	// you can also pass modifiers or a capital ASCII char here
	// warning though: when it sends input, it still considers the
	// modifiers down. So like if you make it MOD_ALT and 'K', and 
send
	// the string 'Hello'... alt is still down, so the program will 
think
	// the user hit alt+H - and thus bring up the Help menu!
         //
         // *** This registers the key with the operating system 
***
	if(!RegisterHotKey(window.impl.hwnd, hotkey_id, 0, VK_F2)) {
		message = "RegisterHotKey failed";
	}

	{
		auto painter = window.draw();
		painter.drawText(Point(0, 0), message);
	}
	window.eventLoop(0); // draw our window
}

// these are bindings to the necessary Windows API functions

import core.sys.windows.windows;

// 
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx
extern(Windows) BOOL RegisterHotKey(HWND, int, UINT, UINT);
// 
http://msdn.microsoft.com/en-us/library/ms646310%28v=vs.85%29.aspx
extern(Windows) UINT SendInput(UINT, INPUT*, int);

struct INPUT {
	DWORD type;
	union {
		MOUSEINPUT mi;
		KEYBDINPUT ki;
		HARDWAREINPUT hi;
	}
}

struct MOUSEINPUT {
	LONG      dx;
	LONG      dy;
	DWORD     mouseData;
	DWORD     dwFlags;
	DWORD     time;
	ULONG_PTR dwExtraInfo;
}

struct KEYBDINPUT {
	WORD      wVk;
	WORD      wScan;
	DWORD     dwFlags;
	DWORD     time;
	ULONG_PTR dwExtraInfo;
}

struct HARDWAREINPUT {
	DWORD uMsg;
	WORD wParamL;
	WORD wParamH;
}

enum INPUT_MOUSE = 0;
enum INPUT_KEYBOARD = 1;
enum INPUT_HARDWARE = 2;

enum MOD_ALT = 0x1;
enum MOD_CONTROL = 0x2;
enum MOD_NOREPEAT = 0x4000; // unsupported
enum MOD_SHIFT = 0x4;
enum MOD_WIN = 0x8; // reserved

enum WM_HOTKEY = 0x0312;

enum KEYEVENTF_EXTENDEDKEY = 0x1;
enum KEYEVENTF_KEYUP = 0x2;
enum KEYEVENTF_SCANCODE = 0x8;
enum KEYEVENTF_UNICODE = 0x4;
Nov 13 2014
next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
Argh some of the lines got split and broken on the email.

to compile:
dmd hotkey.d simpledisplay.d color.d -L/SUBSYSTEM:WINDOWS:5.0


should all be on one line.

Here's the code to compile:
http://arsdnet.net/dcode/hotkey.d


Still read the last message though, the lines got split but I 
added some explanation comments to it that you'll want to see and 
understand to modify it to suit your needs.
Nov 13 2014
prev sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
All right, let's go through each line here too.

On Thursday, 13 November 2014 at 15:59:11 UTC, Adam D. Ruppe 
wrote:

 void sendString(wstring s) {
This function generates key press and key release events for each character in the string, making it a bit more convenient to use than the underlying OS function itself.
 	INPUT[] inputs;
 	inputs.reserve(s.length * 2);

 	foreach(wchar c; s) {
We prepare the array of inputs which stores the information we pass to the operating system.
 		INPUT input;
 		input.type = INPUT_KEYBOARD;
 		input.ki.wScan = c;
 		input.ki.dwFlags = KEYEVENTF_UNICODE;
 		inputs ~= input;
The exact values here come from the MSDN documentation, check the link I provided in a previous message. Basically, we want an INPUT thing, type being the keyboard, and we tell the OS that it is a single Unicode character, value c. Add it to the list of events.
 		input.ki.dwFlags |= KEYEVENTF_KEYUP; // released...
 		inputs ~= input;
This modifies the event to add the key up flag then adds a copy of it to the list. So the key was pressed, then released.
 	if(SendInput(inputs.length, inputs.ptr, INPUT.sizeof) != 
 inputs.length) {
 		import std.stdio;
 		writeln("SendInput failed");
 	}
This function sends our data to Windows to forward to another program as keyboard events. The writeln in there is triggered if it doesn't work - for example, if permission is denied or the data is malformed.
 void main() {
         // uses my simpledisplay.d to pop up a quick window
 	import simpledisplay;
simpledisplay is a little file I wrote that handles a lot of other details involved in creating windows.
 	enum hotkey_id = 1; // arbitrary unique ID for the program
When the operating system tells us that a hotkey was pressed, it sends an ID number to tell us which one. This can be almost any number, we just need to be consistent, so I set it to 1 here.
 	auto window = new SimpleWindow(100, 50);
Creates a 100x50 pixel window using my simpledisplay library.
 	window.handleNativeEvent = delegate int(HWND hwnd, UINT msg, 
 WPARAM wParam, LPARAM lParam) {
simpledisplay.d doesn't provide the specific functionality you need; it doesn't know how to register and react to hotkeys. So we have to extend it to handle those events. It uses delegate event handlers for that purpose.
 		if(hwnd !is window.impl.hwnd)
 			return 1; // we don't care...
just making sure the message is actually for our window, otherwise we ignore it and tell the library to take care of it by returning 1.
 		switch(msg) {
 			case WM_HOTKEY:
The operating system sends many, many different kinds of messages. The type is identified by the msg parameter. Using the switch statement in D, we can filter it do just the one we care about - a hotkey message - handle it, and ignore the rest.
 				if(wParam == hotkey_id) {
Making sure the hotkey ID provided (in the wParam field - see the MSDN docs for this again. they have generic names because each message type has different meanings from these params) matches what we set.
 					// MessageBoxA(window.impl.hwnd, "Hotkey", "Pressed!", 
 MB_OK);
This was just test code, it would pop up a message box saying a key was pressed. It is commented because we wanted to send a string instead.
 					sendString("Hey, it worked!"w);
 					return 0;
Which we do here, sending the string, then return 0 tells the library that we handled this message.
 				}
 			goto default;
 			default: return 1; // not handled, pass it on
 		}
Otherwise, our default behavior is to ignore all other messages and let the library handle them instead.
 	string message = "Hotkey ready";
This message is displayed in the window when you run the program, to give some visual feedback that it is working.
 	if(!RegisterHotKey(window.impl.hwnd, hotkey_id, 0, VK_F2)) {
 		message = "RegisterHotKey failed";
 	}
This informs the operating system that we want to register and reserve a hot key for our use. The params are first, our window which handles the message, the hotkey id used in the message above, then the key itself. The third param is what modifiers need to be pressed. For example, the ctrl or alt keys. I didn't want to have to press those because it complicates things a bit, so I said 0 here - no modifiers required. The fourth param is the key. I talked about this in my last email, VK_F2 is the F2 key. We could also use VK_F4 or even 'Z' to make it on the Z key. (Warning though, if you make it a letter, best to require ctrl or alt and then the sendString function needs to release that modifier then press it again so the program doesn't get confused. Otherwise, it would think the user is still holding ctrl or whatever, and when a 's' is passed along, it will try to save the file because it thought the user hit ctrl+s!)
 	{
 		auto painter = window.draw();
 		painter.drawText(Point(0, 0), message);
 	}
This little bit just draws the message on our window. The surrounding {} is a requirement from simpledisplay.d - it buffers all drawing actions until the next } (when the painter goes out of scope) and we want it to draw before entering the loop.
 	window.eventLoop(0); // draw our window
And finally we go into the loop, where the window is actually drawn and we react to user actions. Most GUI programs have a line or lines similar to this. Internally it looks like while(!window.closed) { window.handleNextMessage(); }
 // these are bindings to the necessary Windows API functions
And the rest of the file is just copy/pasting the function names and params, constant values, and struct layouts from MSDN, like i said before. Ideally, this would all just be in an imported file too, but D doesn't come with one for this purpose and it is easier to list them here than try searching the web and downloading one since we don't need that many.
Nov 13 2014