Basically want to make a macro script
Casey via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Nov 13 21:02:38 PST 2014
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!
More information about the Digitalmars-d-learn
mailing list