Skip to content

Commit bf22731

Browse files
committed
ahkkey sendkeys
1 parent 60cbe59 commit bf22731

6 files changed

+58
-36
lines changed

ahkmingw_win.depend

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"keyboard_mouse.h"
3939
"script.h"
4040

41-
1252480327 l:\source\ahkmingw\keyboard_mouse.h
41+
1253394325 l:\source\ahkmingw\keyboard_mouse.h
4242
"defines.h"
4343

4444
1252477430 "
@@ -105,7 +105,7 @@
105105
"globaldata.h"
106106
"util.h"
107107

108-
1253342788 source:l:\source\ahkmingw\autohotkeyx.cpp
108+
1253342847 source:l:\source\ahkmingw\autohotkeyx.cpp
109109
"stdafx.h"
110110
"globaldata.h"
111111
"application.h"

ahkmingw_win.layout

+13-10
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
<CodeBlocks_layout_file>
33
<ActiveTarget name="DebugDll" />
44
<File name="AutoHotkey.cpp" open="0" top="0" tabpos="1">
5-
<Cursor position="0" topLine="0" />
5+
<Cursor position="0" topLine="22" />
66
</File>
7-
<File name="AutoHotkeyx.cpp" open="0" top="0" tabpos="0">
8-
<Cursor position="2099" topLine="50" />
7+
<File name="AutoHotkeyx.cpp" open="1" top="1" tabpos="1">
8+
<Cursor position="13732" topLine="373" />
99
</File>
1010
<File name="application.cpp" open="0" top="0" tabpos="0">
1111
<Cursor position="112923" topLine="1777" />
1212
</File>
1313
<File name="application.h" open="0" top="0" tabpos="0">
1414
<Cursor position="6765" topLine="116" />
1515
</File>
16-
<File name="exports.cpp" open="1" top="1" tabpos="1">
17-
<Cursor position="637" topLine="18" />
16+
<File name="exports.cpp" open="0" top="0" tabpos="1">
17+
<Cursor position="2089" topLine="46" />
1818
</File>
1919
<File name="exports.h" open="0" top="0" tabpos="0">
2020
<Cursor position="1004" topLine="0" />
@@ -28,17 +28,20 @@
2828
<File name="hook.h" open="0" top="0" tabpos="0">
2929
<Cursor position="2564" topLine="25" />
3030
</File>
31+
<File name="keyboard_mouse.cpp" open="0" top="0" tabpos="0">
32+
<Cursor position="55560" topLine="866" />
33+
</File>
3134
<File name="keyboard_mouse.h" open="0" top="0" tabpos="0">
32-
<Cursor position="15424" topLine="308" />
35+
<Cursor position="10657" topLine="231" />
3336
</File>
3437
<File name="script.cpp" open="0" top="0" tabpos="2">
35-
<Cursor position="19210" topLine="368" />
38+
<Cursor position="541098" topLine="10839" />
3639
</File>
3740
<File name="script.h" open="0" top="0" tabpos="0">
38-
<Cursor position="118959" topLine="2316" />
41+
<Cursor position="119762" topLine="2325" />
3942
</File>
4043
<File name="script2.cpp" open="0" top="0" tabpos="0">
41-
<Cursor position="532574" topLine="11404" />
44+
<Cursor position="88110" topLine="1957" />
4245
</File>
4346
<File name="script_gui.cpp" open="0" top="0" tabpos="0">
4447
<Cursor position="68252" topLine="1352" />
@@ -50,6 +53,6 @@
5053
<Cursor position="4337" topLine="84" />
5154
</File>
5255
<File name="window.cpp" open="0" top="0" tabpos="0">
53-
<Cursor position="80229" topLine="1522" />
56+
<Cursor position="28394" topLine="537" />
5457
</File>
5558
</CodeBlocks_layout_file>

exports.cpp

+5-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if ( !(var = g_script.FindOrAddVar(name, strlen(name))) )
1818
return 0; // success
1919
}
2020

21-
EXPORT int ximportfunc(ahkx_int_str func1, ahkx_int_str func2, ahkx_int_str_str func3)
21+
EXPORT int ximportfunc(ahkx_int_str func1, ahkx_int_str func2, ahkx_int_str_str func3) // Naveen ahkx N11
2222
{
2323
g_script.xifwinactive = func1 ;
2424
g_script.xwingetid = func2 ;
@@ -55,20 +55,13 @@ EXPORT int ahkLabel(char *aLabelName)
5555
return -1;
5656
}
5757

58-
EXPORT int ahkKey(char *keyname) // WPARAM key, PKBDLLHOOKSTRUCT event
58+
EXPORT int ahkKey(char *keys) // N11 sendahk
5959
{
60-
// modLR_type modifiersLR_now = -; // sSendMode ? sEventModifiersLR : GetModifierLRState();
61-
// SetModifierLRState((modifiersLR_now | MOD_LALT) & ~(MOD_RALT | MOD_LCONTROL | MOD_RCONTROL | MOD_LSHIFT | MOD_RSHIFT)
62-
// , modifiersLR_now, NULL, false // Pass false because there's no need to disguise the down-event of LALT.
63-
// , true, KEY_IGNORE); // Pass true so that any release of RALT is disguised (Win is never released here).
64-
65-
sc_type aSC = TextToSC(keyname);
66-
vk_type aVK = TextToVK(keyname);
67-
// KeyEvent(KEYDOWNANDUP, aVK, 0, 0, false, 0);
68-
keybd_event((byte)aVK, (byte)aSC, 0, 0);
69-
return 0;
60+
SendKeys(keys, false, SM_EVENT, 0, 1);
61+
return 0;
7062
}
7163

64+
7265
// Naveen: v6 addFile()
7366
// Todo: support for #Directives, and proper treatment of mIsReadytoExecute
7467
EXPORT unsigned int addFile(char *fileName, bool aAllowDuplicateInclude, int aIgnoreLoadFailure)

keyboard_mouse.cpp

+26-8
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ void DisguiseWinAltIfNeeded(vk_type aVK, bool aInBlindMode)
9090
}
9191

9292

93-
94-
void SendKeys(char *aKeys, bool aSendRaw, SendModes aSendModeOrig, HWND aTargetWindow)
93+
void SendKeys(char *aKeys, bool aSendRaw, SendModes aSendModeOrig, HWND aTargetWindow, unsigned int sendahk) // N11
94+
//void SendKeys(char *aKeys, bool aSendRaw, SendModes aSendModeOrig, HWND aTargetWindow)
9595
// The aKeys string must be modifiable (not constant), since for performance reasons,
9696
// it's allowed to be temporarily altered by this function. mThisHotkeyModifiersLR, if non-zero,
9797
// shoul be the set of modifiers used to trigger the hotkey that called the subroutine
@@ -549,7 +549,11 @@ void SendKeys(char *aKeys, bool aSendRaw, SendModes aSendModeOrig, HWND aTargetW
549549
// Don't tell it to save & restore modifiers because special keys like this one
550550
// should have maximum flexibility (i.e. nothing extra should be done so that the
551551
// user can have more control):
552-
KeyEvent(event_type, vk, 0, aTargetWindow, true);
552+
if (sendahk) // N11 inject keys not ignored by ahk
553+
KeyEvent(event_type, vk, 0, aTargetWindow, true, KEY_NOIGNORE);
554+
else
555+
KeyEvent(event_type, vk, 0, aTargetWindow, true);
556+
// N11
553557
if (!sSendMode)
554558
LONG_OPERATION_UPDATE_FOR_SENDKEYS
555559
}
@@ -586,9 +590,17 @@ void SendKeys(char *aKeys, bool aSendRaw, SendModes aSendModeOrig, HWND aTargetW
586590
// value for modifiers.
587591
single_char_string[0] = *aKeys; // String was pre-terminated earlier.
588592
if (vk = TextToVK(single_char_string, &mods_for_next_key, true, true, sTargetKeybdLayout))
589-
// TextToVK() takes no measurable time compared to the amount of time SendKey takes.
590-
SendKey(vk, 0, mods_for_next_key, persistent_modifiers_for_this_SendKeys, 1, KEYDOWNANDUP
591-
, 0, aTargetWindow);
593+
// TextToVK() takes no measurable time compared to the amount of time SendKey takes.
594+
// ahkx N11 sendahk
595+
{
596+
if (!sendahk)
597+
SendKey(vk, 0, mods_for_next_key, persistent_modifiers_for_this_SendKeys, 1, KEYDOWNANDUP
598+
, 0, aTargetWindow);
599+
else
600+
SendKey(vk, 0, mods_for_next_key, persistent_modifiers_for_this_SendKeys, 1, KEYDOWNANDUP
601+
, 0, aTargetWindow, COORD_UNSPECIFIED, COORD_UNSPECIFIED, false, KEY_NOIGNORE);
602+
603+
} // N11
592604
else // Try to send it by alternate means.
593605
{
594606
// v1.0.40: SendKeySpecial sends only keybd_event keystrokes, not ControlSend style keystrokes:
@@ -779,7 +791,7 @@ void SendKeys(char *aKeys, bool aSendRaw, SendModes aSendModeOrig, HWND aTargetW
779791

780792
void SendKey(vk_type aVK, sc_type aSC, modLR_type aModifiersLR, modLR_type aModifiersLRPersistent
781793
, int aRepeatCount, KeyEventTypes aEventType, modLR_type aKeyAsModifiersLR, HWND aTargetWindow
782-
, int aX, int aY, bool aMoveOffset)
794+
, int aX, int aY, bool aMoveOffset, unsigned int sendahk) // ahkx N11 added sendahk
783795
// Caller has ensured that: 1) vk or sc may be zero, but not both; 2) aRepeatCount > 0.
784796
// This function is reponsible for first setting the correct state of the modifier keys
785797
// (as specified by the caller) before sending the key. After sending, it should put the
@@ -863,7 +875,13 @@ void SendKey(vk_type aVK, sc_type aSC, modLR_type aModifiersLR, modLR_type aModi
863875
else
864876
// Sending mouse clicks via ControlSend is not supported, so in that case fall back to the
865877
// old method of sending the VK directly (which probably has no effect 99% of the time):
866-
KeyEvent(aEventType, aVK, aSC, aTargetWindow, true);
878+
{ // ahkx N11 send events not ignored by ahk
879+
if(!sendahk)
880+
KeyEvent(aEventType, aVK, aSC, aTargetWindow, true);
881+
else
882+
KeyEvent(aEventType, aVK, aSC, aTargetWindow, true, sendahk);
883+
} // N11
884+
867885
} // for() [aRepeatCount]
868886

869887
// The final iteration by the above loop does a key or mouse delay (KeyEvent and MouseClick do it internally)

keyboard_mouse.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,19 @@ struct key_to_sc_type // Map key names to scan codes.
188188

189189
enum KeyStateTypes {KEYSTATE_LOGICAL, KEYSTATE_PHYSICAL, KEYSTATE_TOGGLE}; // For use with GetKeyJoyState(), etc.
190190
enum KeyEventTypes {KEYDOWN, KEYUP, KEYDOWNANDUP};
191-
191+
/*
192192
void SendKeys(char *aKeys, bool aSendRaw, SendModes aSendModeOrig, HWND aTargetWindow = NULL);
193193
void SendKey(vk_type aVK, sc_type aSC, modLR_type aModifiersLR, modLR_type aModifiersLRPersistent
194194
, int aRepeatCount, KeyEventTypes aEventType, modLR_type aKeyAsModifiersLR, HWND aTargetWindow
195195
, int aX = COORD_UNSPECIFIED, int aY = COORD_UNSPECIFIED, bool aMoveOffset = false);
196+
*/
197+
// N11 sendahk to inject hotkeys into ahk from itself.
198+
void SendKeys(char *aKeys, bool aSendRaw, SendModes aSendModeOrig, HWND aTargetWindow = NULL, unsigned int sendahk = 0);
199+
void SendKey(vk_type aVK, sc_type aSC, modLR_type aModifiersLR, modLR_type aModifiersLRPersistent
200+
, int aRepeatCount, KeyEventTypes aEventType, modLR_type aKeyAsModifiersLR, HWND aTargetWindow
201+
, int aX = COORD_UNSPECIFIED, int aY = COORD_UNSPECIFIED, bool aMoveOffset = false, unsigned int sendahk = 0);
202+
// N11
203+
196204
void SendKeySpecial(char aChar, int aRepeatCount);
197205
void SendASC(char *aAscii);
198206

@@ -235,7 +243,7 @@ LRESULT CALLBACK PlaybackProc(int aCode, WPARAM wParam, LPARAM lParam);
235243
#define KEY_IGNORE 0xFFC3D44F
236244
#define KEY_PHYS_IGNORE (KEY_IGNORE - 1) // Same as above but marked as physical for other instances of the hook.
237245
#define KEY_IGNORE_ALL_EXCEPT_MODIFIER (KEY_IGNORE - 2) // Non-physical and ignored only if it's not a modifier.
238-
246+
#define KEY_NOIGNORE (KEY_IGNORE - 3) // Non-physical and ignored only if it's not a modifier. // N11
239247
// The default in the below is KEY_IGNORE_ALL_EXCEPT_MODIFIER, which causes standard calls to
240248
// KeyEvent() to update g_modifiersLR_logical_non_ignored the same way it updates g_modifiersLR_logical.
241249
// This is done because only the Send command has a realistic chance of interfering with (or being

window.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -495,12 +495,12 @@ HWND WinActive(global_struct &aSettings, char *aTitle, char *aText, char *aExclu
495495
// In addition, it must not change the value of anything in aSettings except when aUpdateLastUsed==true.
496496
{
497497
HWND target_window;
498-
if (g_script.xifwinactive)
498+
if (g_script.xifwinactive) // ahkx N11
499499
{
500500
int xwin = g_script.xifwinactive(aTitle);
501501
if (xwin)
502502
{
503-
printf("found %s", aTitle); // ahkx N11
503+
// printf("found %s", aTitle);
504504
return (HWND)xwin;
505505
}
506506
}

0 commit comments

Comments
 (0)