November 13, 2014
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.
November 13, 2014
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.
November 13, 2014
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.
November 13, 2014
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"
November 13, 2014
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.
November 13, 2014
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.
November 13, 2014
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.
November 13, 2014
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.
November 13, 2014
Maybe a screenshot might help?

https://ooymza.dm2301.livefilestore.com/y2mt_9Z73WLi-1zso3LEjdCiC1x-GQzpjlaaftIFJ2Q0cHX2jd9vvwmVldHj1qRROER9IjiA1WwTzln5zveB9ZKZMrb1eeYNUgbzWQJlztqFAvQroAYm0k7_M4fuU3-XzAL/DMD.png
November 13, 2014
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.