November 13, 2014
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.
November 13, 2014
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
ever been able to accomplish this task with C# and InputSimulator.
November 13, 2014
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
> ever been able to accomplish this task with C# and 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.
November 13, 2014
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.
November 13, 2014
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
>> ever been able to accomplish this task with C# and 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!
November 13, 2014
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
>>> ever been able to accomplish this task with C# and 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!

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
November 13, 2014
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;
November 13, 2014
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.
November 13, 2014
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.
November 13, 2014
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!