Hi, I am going to simulate key press in my cpp code directly. I use sendinput func in cpp, but is not work well. I don't know why sendinput just not worked in some window, even when I try the instructions mentioned on Stack Overflow to use the scancode.
But when I try ahk exe the key send normally, so I want to simulate the ahk l way to send key stroke. I checked the code of ahk_l on github already,
iit's a huge project, I don't know where to start.
Anyone can give me some advice about the source code of ahk _L ?
thx ~
how to simulate the key send as the ahk L do in cpp? Topic is solved
-
- Posts: 117
- Joined: 05 Oct 2015, 21:23
Re: how to simulate the key send as the ahk L do in cpp? Topic is solved
Maybe a simpler solution would be to use AutoHotkey.dll
You could load that libary from your C code, then simply call AHK's send function from your C code.
https://hotkeyit.github.io/v2/docs/AutoHotkeyDll.htm
Don't worry about the V2 stuff, there is a dll for V1 too
You could load that libary from your C code, then simply call AHK's send function from your C code.
https://hotkeyit.github.io/v2/docs/AutoHotkeyDll.htm
Don't worry about the V2 stuff, there is a dll for V1 too
-
- Posts: 117
- Joined: 05 Oct 2015, 21:23
Re: how to simulate the key send as the ahk L do in cpp?
thx for your timely reply, but I get some problem when call the dll from cpp.evilC wrote: ↑13 Feb 2019, 07:36Maybe a simpler solution would be to use AutoHotkey.dll
You could load that libary from your C code, then simply call AHK's send function from your C code.
https://hotkeyit.github.io/v2/docs/AutoHotkeyDll.htm
Don't worry about the V2 stuff, there is a dll for V1 too
Here is my code, I copy it from this link : https://autohotkey.com/board/topic/39588-autohotkeydll/://autohotkey.com/board/topic/39588-autohotkeydll/page-28?&#entry418330, written by hotkeyit.
and download the dll from : https://codeload.github.com/HotKeyIt/ahkdll-v2-release/zip/master.
When I run the code I get :
. Empty msgbox without text "ahk".
If I change the msgbox ahk to "send test", nothing happens. So how to call the dll properly? Tnx.
Code: Select all
#include <windows.h>
int main(void)
{
typedef BOOL (*pahkReady)(void); //Typedef the functions
typedef BOOL (*pahkExec)(LPTSTR script);
typedef UINT (*pahkdll)(LPTSTR script,LPTSTR p1,LPTSTR p2);
HINSTANCE hdll = LoadLibrary("[color=red]C:\\Windows\\System32\\AutoHotkey.dll[/color]"); // Load Library
pahkdll ahkdll = (pahkdll)GetProcAddress(hdll, "ahkdll"); // assign function pointers
pahkReady ahkReady = (pahkReady)GetProcAddress(hdll, "ahkReady");
pahkExec ahkExec = (pahkExec)GetProcAddress(hdll, "ahkExec");
ahkdll("","",""); // start fresh AutoHotkey in #Persistent mode
while (!ahkReady()) // wait for AutoHotkey
Sleep(10);
ahkExec("Msgbox AHK"); //execute a script
return 0;
}
Re: how to simulate the key send as the ahk L do in cpp?
ahkExec("Msgbox AHK");
Msgbox AHK string literals need to be quoted in v2. AHK refers to an empty variable in this context, hence the empty msgbox. wrap it in quotes or download the v1.dll if u wanna keep writing it that way
Msgbox AHK string literals need to be quoted in v2. AHK refers to an empty variable in this context, hence the empty msgbox. wrap it in quotes or download the v1.dll if u wanna keep writing it that way
-
- Posts: 117
- Joined: 05 Oct 2015, 21:23
Re: how to simulate the key send as the ahk L do in cpp?
tnx my bro, the code worked.
Code: Select all
ahkExec(TEXT("Msgbox \"AHK\"")); //execute a script
// same goes with the send command
ahkExec(TEXT("Send \"{lalt down}\""));
How do you know the difference where can I get the manual of how to use it. V2 is better than V1?
Any examples for V2? Thank you again.
Re: how to simulate the key send as the ahk L do in cpp?
If all you want to do is send keys, then v1 or v2 will make no real difference I don't think.
-
- Posts: 117
- Joined: 05 Oct 2015, 21:23
Re: how to simulate the key send as the ahk L do in cpp?
Use AhkGetVar to retrieve the variable value from the script
https://hotkeyit.github.io/v2/docs/commands/ahkgetvar.htm
https://hotkeyit.github.io/v2/docs/commands/ahkgetvar.htm
-
- Posts: 117
- Joined: 05 Oct 2015, 21:23
Re: how to simulate the key send as the ahk L do in cpp?
sorry to asking you so many questions but these things really tough to get through google.evilC wrote: ↑15 Feb 2019, 10:44Use AhkGetVar to retrieve the variable value from the script
https://hotkeyit.github.io/v2/docs/commands/ahkgetvar.htm
One more question, how to make two ahk stament in a dll call.
For example :
Code: Select all
CoordMode mouse, screen
click, 100, 100
The coordmode is default set to current window,
I try to call the dll twice like this, but the coordmode won't changed when click the mouse.
Code: Select all
ahkExec("coordmode \"mouse, screen\"");
ahkExec("click \"100,100\"");
Re: how to simulate the key send as the ahk L do in cpp?
AHKExec is more for executing one-off code. It may well be fine for what you want - to run multiple commands, you probably just have to add newlines.
If you want to start a proper AHK thread, you probably want ahkThread.
If you want to see some usage examples for that, see here: https://github.com/evilC/UCR/blob/master/Classes/UCRMain.ahk#L869
Here, AHK is the calling language, but the way you initialize and communicate with the thread should basically be the same.
If you want to start a proper AHK thread, you probably want ahkThread.
If you want to see some usage examples for that, see here: https://github.com/evilC/UCR/blob/master/Classes/UCRMain.ahk#L869
Here, AHK is the calling language, but the way you initialize and communicate with the thread should basically be the same.
Who is online
Users browsing this forum: Spawnova and 99 guests