Re: Experience report on installing dmd 2.066.1 on OSX
On Thursday, 13 November 2014 at 05:57:49 UTC, Joakim wrote: On Wednesday, 12 November 2014 at 22:38:56 UTC, Ali Çehreli wrote: A friend of mine installed dmd on OSX and recorded his experiences: http://cap-lore.com/Languages/D/Install.html I wonder why he had to do manual work like running xattr. Is that expected on OSX? Looks like they're now requiring that apps be signed with the developer's account, which I'm guessing the dmd dmg isn't: http://stackoverflow.com/questions/24176378/why-my-dmg-is-not-getting-opened-without-asking-security-popup Downloading the zip is still the most simple and easy way, IMHO... Not a single problem on 10.10... --- Paolo
Re: Can't install dub on Debian
El 13/11/14 a les 07:29, Suliman via Digitalmars-d-learn ha escrit: ... Description:Debian GNU/Linux 6.0.9 (squeeze) ... packages on d-apt repository are created for multiarch systems, Debian 7.x.x and Ubuntu 12.04. Old stable Debian 6.x.x is not. If you want to install dub deb package from d-apt on Debian 6.x.x I recomend you to install first the all-in-one dmd deb package from dlang.org: http://downloads.dlang.org/releases/2014/dmd_2.066.1-0_amd64.deb then try to install dub deb package again. You can download it from here: http://sourceforge.net/projects/d-apt/files/pool/main/d/dub/dub_0.9.22-0_amd64.deb/download I cannot assure that you will be able to install this dub deb package because it is designed for multi-arch systems. Regards, -- Jordi Sayol
Re: Crash on Windows with core.stdc.stdlib.free()
On Wednesday, 12 November 2014 at 16:10:34 UTC, ketmar via Digitalmars-d-learn wrote: On Wed, 12 Nov 2014 16:03:08 + Chris via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Wednesday, 12 November 2014 at 14:42:34 UTC, Chris wrote: On Wednesday, 12 November 2014 at 14:26:15 UTC, ketmar via if you can extend C DLL, just add wrapper for `free()` there. so you will not call `free()` from D, but call C DLL function which will free the memory. it's a good practice anyway, 'cause it's recommended to free memory in the same library where you allocated it. I initially had an implementation that did exactly that (I usually do that), but for some reason it didn't work properly in this particular case and caused all sorts of undefined behavior. But I'll have a look at it again. I've changed the code so that the memory is freed in C. Although it works better it crashes too every now and then (WindowsError : exception : access violation writing 0x0310A1B4) Will look into it. this also can happen due to allocators conflict somehow. or due to other code which stores the pointer somewhere and then accesses the memory. i think that it will be hard to trace without debugger. Thanks a million! Just checked it this morning. It was the latter. I kept a reference to short* data in a class variable in D and didn't clear that reference when freeing the memory in the C library. Interesting though that it never crashes on Linux, only on Windows did this cause problems. It is also interesting that core.stdc.stdlib.free() and free() in the C library produced a slightly different crash behavior. But that might be down to the fact that the two happen in different places in the program.
Re: Crash on Windows with core.stdc.stdlib.free()
On Thu, 13 Nov 2014 10:08:47 + Chris via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Interesting though that it never crashes on Linux, only on Windows did this cause problems. seems that libc allocator is not marking free pages as unreadable, and windows libc allocator does something like this. i got alot of such use after free things in my C code, but valgrind is brilliant to track that down. i miss valgrind on windows. ;-) now i prefer to write code in GNU/Linux if possible and use valgrind to track down memory issues, and only after it works on linux and valgrind is happy, i'm starting to port it to windows. this, of course, hard to do with winapi-tied code, but wine/winelib can help there too (to some extent). signature.asc Description: PGP signature
Re: Can't install dub on Debian
You are right, after updating Debian to 7.7 dub was installed successfully
Re: Experience report on installing dmd 2.066.1 on OSX
On Wednesday, 12 November 2014 at 22:38:56 UTC, Ali Çehreli wrote: A friend of mine installed dmd on OSX and recorded his experiences: http://cap-lore.com/Languages/D/Install.html I wonder why he had to do manual work like running xattr. Is that expected on OSX? Thank you, Ali It is blocked initially as it's not from an identified developer, but going to security options gives you a one-time opt-out to let it through. Alternatively, you can permanantly reduce your security settings. That's just how OS X works these days.
have function must pass delegate.
A method call in the GTK API takes a delegate as an argument(addOnActivate) I would like to be able to pass a function instead (address of). What is the solution, at present I have a wrapper class around the function.
Re: have function must pass delegate.
On Thu, 13 Nov 2014 14:02:22 + Spacen Jasset via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: A method call in the GTK API takes a delegate as an argument(addOnActivate) I would like to be able to pass a function instead (address of). What is the solution, at present I have a wrapper class around the function. std.functional has `toDelegate`. signature.asc Description: PGP signature
Callbacks in D as void functions
Hi all, I already posted this to Code Project, but maybe you have a solution for my problem. I am trying to write a wrapper for a C API in D. In C I have the following definition of a callback type: typedef void (*Callback)(void*); In a struct all members are of the type Callback. In the main function each member is assigned a function like this: Events.OnData = MyDtaCB; Here the MyDtaCB function has no prototype but is defined as follows: void MyDtaCB(void* pVoid){ // Do stuff } Now I tried to port this to D. The wiki says that callback functions should be declared as integer functions, so my D code looks like this: extern (C) alias CEventCallback_t = int function(int, int); extern (C) CEventCallback_t MyDtaCB(void*); Here's the catch: when I try to assign the MyDtaCB function to a member of the Events struct, I get a compilation error because MyDtaCB is a void function and therefore returns no value. Seems to work in C, though, but I don't know how to handle this in D. The D tutorial has a function called getCallback() which returns the void function but itself has the Callback type as return value. However, in D this would lead to the same error as before since the void function has no non-empty return value. Any suggestions how to accomplish this? My thought now was to screw the function definitions of the C API and implement them in D. But what's the point in having the API then? Thanks in advance.
Re: Callbacks in D as void functions
Wsdes: The wiki says that callback functions should be declared as integer functions, What's bad in returning void? Bye, bearophile
Does the compiler always semantically analyze everything in a project?
Specifically, when I put some code in a separately compiled lib, does that save me anything in terms of files that have to be analyzed or will dmd always go through every file that can be reached through includes ? (.di files are out of question, because they have issues) -- Marco
Re: Callbacks in D as void functions
On 11/13/14 9:49 AM, Wsdes wrote: Hi all, I already posted this to Code Project, but maybe you have a solution for my problem. I am trying to write a wrapper for a C API in D. In C I have the following definition of a callback type: typedef void (*Callback)(void*); in D, this would be: alias Callback = void function(void *); In a struct all members are of the type Callback. In the main function each member is assigned a function like this: Events.OnData = MyDtaCB; Here the MyDtaCB function has no prototype but is defined as follows: void MyDtaCB(void* pVoid){ // Do stuff } Now I tried to port this to D. The wiki says that callback functions should be declared as integer functions, so my D code looks like this: extern (C) alias CEventCallback_t = int function(int, int); extern (C) CEventCallback_t MyDtaCB(void*); This doesn't look right. MyDtaCB is a function taking void *, that returns a function pointer. Can you point at the wiki you are talking about? Here's the catch: when I try to assign the MyDtaCB function to a member of the Events struct, I get a compilation error because MyDtaCB is a void function and therefore returns no value. Seems to work in C, though, but I don't know how to handle this in D. C is a lot looser in function pointer types. Without more context of what you are doing, it's hard to diagnose this any further. -Steve
Re: Callbacks in D as void functions
On Thursday, 13 November 2014 at 14:50:00 UTC, Wsdes wrote: I am trying to write a wrapper for a C API in D. In C I have the following definition of a callback type: typedef void (*Callback)(void*); I would translate this directly to D: extern(C) alias Callback = void function(void*); Here the MyDtaCB function has no prototype but is defined as follows: void MyDtaCB(void* pVoid){ // Do stuff } And don't forget extern(C) on this too: extern(C) void MyDtaCB(void* pVoid) { } And assign it to the struct: Events.OnData = MyDtaCB; Unless you have a link to the wiki that talks about ints, maybe that says something different, but I like to keep my C and D code that calls it looking pretty much the same when I can.
Re: Callbacks in D as void functions
On Thursday, 13 November 2014 at 15:17:45 UTC, Adam D. Ruppe wrote: On Thursday, 13 November 2014 at 14:50:00 UTC, Wsdes wrote: I am trying to write a wrapper for a C API in D. In C I have the following definition of a callback type: typedef void (*Callback)(void*); I would translate this directly to D: extern(C) alias Callback = void function(void*); Here the MyDtaCB function has no prototype but is defined as follows: void MyDtaCB(void* pVoid){ // Do stuff } And don't forget extern(C) on this too: extern(C) void MyDtaCB(void* pVoid) { } And assign it to the struct: Events.OnData = MyDtaCB; Unless you have a link to the wiki that talks about ints, maybe that says something different, but I like to keep my C and D code that calls it looking pretty much the same when I can. Hi, thank you everybody for your replies. First of all, the link to the wiki that has an example of callbacks in C and D: http://dlang.org/interfaceToC.html Secondly, I tried your code and that was exactly what I was thinking and what I tried before. Then I thought I'd turn to the wiki example, so that's where the int function came from. In the meantime I changed that to return void so I gave you my old code :( Anyway, I think I got the problem solved. Well, there seems to never have been any problem as I am taught now. I asked the developer of the C API this morning if I should try to implement the callback functions redundantly in D and he said he will have a look with me later. So now it turns out that I cannot call the extern callback function because it's not provided within the library O.O I was already wondering why there are no prototypes to these callback functions but I assumed they are provided from another library that I don't have direct access to... So the solution to my problem finally is to define the function in my D file and then cast the function pointer to the Callback type like this: void MyDtaCB(void* v){ // Do stuff } Events.OnData = cast(Callback) MyDtaCB; At least this one compiles. Now I'm facing other problems with struct members but I guess I'll figure this out. If not, I'll ask again so stay tuned for some more unsolved mysteries ;) Still, thank you all for your effort and time. Keep it up! :)
Re: Basically want to make a macro script
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;
Re: Basically want to make a macro script
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.
Re: Basically want to make a macro script
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.
Re: Callbacks in D as void functions
On Thursday, 13 November 2014 at 15:58:34 UTC, Wsdes wrote: void MyDtaCB(void* v){ // Do stuff } Events.OnData = cast(Callback) MyDtaCB; this compiles but might crash, the extern(C) is important on a callback to be used from a C program. I'd really recommend adding that to the function, even if you cast when assigning to the struct.
Re: Does the compiler always semantically analyze everything in a project?
Apart from unused templates - yes. In abscence of .di files separate compilation only affects generated object files
Re: Callbacks in D as void functions
On 11/13/14 10:58 AM, Wsdes wrote: First of all, the link to the wiki that has an example of callbacks in C and D: http://dlang.org/interfaceToC.html Secondly, I tried your code and that was exactly what I was thinking and what I tried before. Then I thought I'd turn to the wiki example, so that's where the int function came from. In the meantime I changed that to return void so I gave you my old code :( The int example in the above wiki page (not technically a wiki, but that's OK) is because the function type in C is ALSO taking ints :) Not all callback functions are the same. Your callback type in D should be the same as the C definition, but with extern(C). Can you tell us the exact prototype of the function you are trying to assign, whether it is a member of a struct, class, or is an inner function, and the exact prototype you declared the Callback type to be? I don't need to see any code of the function. -Steve
Re: Does the compiler always semantically analyze everything in a project?
Am Thu, 13 Nov 2014 16:54:45 + schrieb Dicebot pub...@dicebot.lv: Apart from unused templates - yes. In abscence of .di files separate compilation only affects generated object files I thought so and wonder how that will scale with large code bases. Lately I found so many bugs and shortcomings that the ice is growing thin. There's bugs with .di files, with separate compilation, with SIMD, static dtors inside templates... and no the uncertainty how D projects will scale if the module with main imports the world. It makes me want to switch to C++. :p I hope Walter's idea of full lazy evaluation can help here. -- Marco
Re: Basically want to make a macro script
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!
Re: Basically want to make a macro script
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.
Re: Basically want to make a macro script
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.
Re: Basically want to make a macro script
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\Caseydmd 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\Caseydmd 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\Caseydmd 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
Re: Basically want to make a macro script
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\Caseydmd 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\Caseydmd 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\Caseydmd 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
Re: Basically want to make a macro script
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
Re: Basically want to make a macro script
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.
Re: Basically want to make a macro script
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.
Re: Basically want to make a macro script
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\Caseydmd 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\Caseydmd 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\Caseydmd 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)
Re: Basically want to make a macro script
Maybe a screenshot might help? https://ooymza.dm2301.livefilestore.com/y2mt_9Z73WLi-1zso3LEjdCiC1x-GQzpjlaaftIFJ2Q0cHX2jd9vvwmVldHj1qRROER9IjiA1WwTzln5zveB9ZKZMrb1eeYNUgbzWQJlztqFAvQroAYm0k7_M4fuU3-XzAL/DMD.png
Re: Basically want to make a macro script
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.
Re: Basically want to make a macro script
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\Ddmd Keybinds.d simpledisplay.d color.d Keybinds.d(11): Error: undefined identifier KEYEVENTF_UNICODE Not sure what to do at this point.
Re: Basically want to make a macro script
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\Ddmd 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.
Re: Basically want to make a macro script
On Thursday, 13 November 2014 at 23:54:13 UTC, Casey wrote: D:\Documents\Other\Hotkeys\Ddmd 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.
Re: Basically want to make a macro script
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\Ddmd 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.
Re: Callbacks in D as void functions
On 11/14/2014 12:58 AM, Wsdes wrote: Anyway, I think I got the problem solved. Well, there seems to never have been any problem as I am taught now. I asked the developer of the C API this morning if I should try to implement the callback functions redundantly in D and he said he will have a look with me later. So now it turns out that I cannot call the extern callback function because it's not provided within the library O.O I was already wondering why there are no prototypes to these callback functions but I assumed they are provided from another library that I don't have direct access to... Callbacks wouldn't be implemented in the library. They are intended to be implemented by the user of the library. That's why they're called callbacks. The library calls back your function. In C, this is how event programming is usually handled. You pass a function pointer to the library and when some event occurs, the library calls your function (the callback). So the solution to my problem finally is to define the function in my D file and then cast the function pointer to the Callback type like this: void MyDtaCB(void* v){ // Do stuff } Events.OnData = cast(Callback) MyDtaCB; Define it as extern( C ) and you don't need the cast. extern( C ) MyDtaCB( void* v ) { ... } Events.OnData = MyDtaCB; Callbacks intended to be passed to C should *always* be implemented as extern( C ).
Re: Basically want to make a macro script
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.
Kitchen Designs UK
Kitchen Designs UK. Thirty Ex Display Kitchens To Clear. www.exdisplaykitchens1.co.uk £ 595 Each with appliances. Tel 01616-694785
Re: Basically want to make a macro script
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.
Re: Basically want to make a macro script
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.
Re: Basically want to make a macro script
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