"Fossies" - the Fresh Open Source Software Archive

Member "AutoHotkey_L-1.1.33.09/source/globaldata.h" (8 May 2021, 14158 Bytes) of package /windows/misc/AutoHotkey_L-1.1.33.09.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "globaldata.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2 AutoHotkey
    3 
    4 Copyright 2003-2009 Chris Mallett (support@autohotkey.com)
    5 
    6 This program is free software; you can redistribute it and/or
    7 modify it under the terms of the GNU General Public License
    8 as published by the Free Software Foundation; either version 2
    9 of the License, or (at your option) any later version.
   10 
   11 This program is distributed in the hope that it will be useful,
   12 but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 GNU General Public License for more details.
   15 */
   16 
   17 #ifndef globaldata_h
   18 #define globaldata_h
   19 
   20 #include "hook.h" // For KeyHistoryItem and probably other things.
   21 #include "clipboard.h"  // For the global clipboard object
   22 #include "script.h" // For the global script object and g_ErrorLevel
   23 #include "os_version.h" // For the global OS_Version object
   24 
   25 #include "Debugger.h"
   26 
   27 extern HINSTANCE g_hInstance;
   28 extern DWORD g_MainThreadID;
   29 extern DWORD g_HookThreadID;
   30 extern CRITICAL_SECTION g_CriticalRegExCache;
   31 
   32 extern UINT g_DefaultScriptCodepage;
   33 
   34 extern bool g_DestroyWindowCalled;
   35 extern HWND g_hWnd;  // The main window
   36 extern HWND g_hWndEdit;  // The edit window, child of main.
   37 extern HWND g_hWndSplash;  // The SplashText window.
   38 extern HFONT g_hFontEdit;
   39 extern HFONT g_hFontSplash;
   40 extern HACCEL g_hAccelTable; // Accelerator table for main menu shortcut keys.
   41 
   42 typedef int (WINAPI *StrCmpLogicalW_type)(LPCWSTR, LPCWSTR);
   43 extern StrCmpLogicalW_type g_StrCmpLogicalW;
   44 extern WNDPROC g_TabClassProc;
   45 
   46 extern modLR_type g_modifiersLR_logical;   // Tracked by hook (if hook is active).
   47 extern modLR_type g_modifiersLR_logical_non_ignored;
   48 extern modLR_type g_modifiersLR_physical;  // Same as above except it's which modifiers are PHYSICALLY down.
   49 extern modLR_type g_modifiersLR_numpad_mask;  // Shift keys temporarily released by Numpad.
   50 extern modLR_type g_modifiersLR_ctrlaltdel_mask; // For excluding AltGr from Ctrl+Alt+Del handling.
   51 
   52 extern key_type *pPrefixKey;
   53 
   54 #ifdef FUTURE_USE_MOUSE_BUTTONS_LOGICAL
   55 extern WORD g_mouse_buttons_logical; // A bitwise combination of MK_LBUTTON, etc.
   56 #endif
   57 
   58 #define STATE_DOWN 0x80
   59 #define STATE_ON 0x01
   60 extern BYTE g_PhysicalKeyState[VK_ARRAY_COUNT];
   61 extern bool g_BlockWinKeys;
   62 extern DWORD g_HookReceiptOfLControlMeansAltGr;
   63 extern DWORD g_IgnoreNextLControlDown;
   64 extern DWORD g_IgnoreNextLControlUp;
   65 
   66 extern BYTE g_MenuMaskKeyVK; // For #MenuMaskKey.
   67 extern USHORT g_MenuMaskKeySC;
   68 
   69 // If a SendKeys() operation takes longer than this, hotkey's modifiers won't be pressed back down:
   70 extern int g_HotkeyModifierTimeout;
   71 extern int g_ClipboardTimeout;
   72 
   73 extern HHOOK g_KeybdHook;
   74 extern HHOOK g_MouseHook;
   75 extern HHOOK g_PlaybackHook;
   76 extern bool g_ForceLaunch;
   77 extern bool g_WinActivateForce;
   78 extern bool g_RunStdIn;
   79 extern WarnMode g_Warn_UseUnsetLocal;
   80 extern WarnMode g_Warn_UseUnsetGlobal;
   81 extern WarnMode g_Warn_UseEnv;
   82 extern WarnMode g_Warn_LocalSameAsGlobal;
   83 extern WarnMode g_Warn_ClassOverwrite;
   84 extern WarnMode g_Warn_Unreachable;
   85 extern SingleInstanceType g_AllowOnlyOneInstance;
   86 extern bool g_persistent;
   87 extern bool g_NoTrayIcon;
   88 #ifdef AUTOHOTKEYSC
   89     extern bool g_AllowMainWindow;
   90 #endif
   91 extern bool g_DeferMessagesForUnderlyingPump;
   92 extern bool g_MainTimerExists;
   93 extern bool g_AutoExecTimerExists;
   94 extern bool g_InputTimerExists;
   95 extern bool g_DerefTimerExists;
   96 extern bool g_SoundWasPlayed;
   97 extern bool g_IsSuspended;
   98 extern BOOL g_WriteCacheDisabledInt64;
   99 extern BOOL g_WriteCacheDisabledDouble;
  100 extern BOOL g_NoEnv;
  101 extern BOOL g_AllowInterruption;
  102 extern int g_nLayersNeedingTimer;
  103 extern int g_nThreads;
  104 extern int g_nPausedThreads;
  105 extern int g_MaxHistoryKeys;
  106 extern DWORD g_InputTimeoutAt;
  107 
  108 extern VarSizeType g_MaxVarCapacity;
  109 extern UCHAR g_MaxThreadsPerHotkey;
  110 extern int g_MaxThreadsTotal;
  111 extern int g_MaxHotkeysPerInterval;
  112 extern int g_HotkeyThrottleInterval;
  113 extern bool g_MaxThreadsBuffer;
  114 extern SendLevelType g_InputLevel;
  115 extern HotkeyCriterion *g_HotCriterion;
  116 extern HotkeyCriterion *g_FirstHotCriterion, *g_LastHotCriterion;
  117 
  118 // Global variables for #if (expression). See globaldata.cpp for comments.
  119 extern UINT g_HotExprTimeout;
  120 extern HWND g_HotExprLFW;
  121 extern HotkeyCriterion *g_FirstHotExpr, *g_LastHotExpr;
  122 
  123 extern int g_ScreenDPI;
  124 extern MenuTypeType g_MenuIsVisible;
  125 extern int g_nMessageBoxes;
  126 extern int g_nInputBoxes;
  127 extern int g_nFileDialogs;
  128 extern int g_nFolderDialogs;
  129 extern InputBoxType g_InputBox[MAX_INPUTBOXES];
  130 extern SplashType g_Progress[MAX_PROGRESS_WINDOWS];
  131 extern SplashType g_SplashImage[MAX_SPLASHIMAGE_WINDOWS];
  132 extern GuiType **g_gui;
  133 extern int g_guiCount, g_guiCountMax;
  134 extern HWND g_hWndToolTip[MAX_TOOLTIPS];
  135 extern MsgMonitorList g_MsgMonitor;
  136 
  137 extern UCHAR g_SortCaseSensitive;
  138 extern bool g_SortNumeric;
  139 extern bool g_SortReverse;
  140 extern int g_SortColumnOffset;
  141 extern Func *g_SortFunc;
  142 
  143 extern TCHAR g_delimiter;
  144 extern TCHAR g_DerefChar;
  145 extern TCHAR g_EscapeChar;
  146 
  147 // Hot-string vars:
  148 extern TCHAR g_HSBuf[HS_BUF_SIZE];
  149 extern int g_HSBufLength;
  150 extern HWND g_HShwnd;
  151 
  152 // Hot-string global settings:
  153 extern int g_HSPriority;
  154 extern int g_HSKeyDelay;
  155 extern SendModes g_HSSendMode;
  156 extern SendRawType g_HSSendRaw;
  157 extern bool g_HSCaseSensitive;
  158 extern bool g_HSConformToCase;
  159 extern bool g_HSDoBackspace;
  160 extern bool g_HSOmitEndChar;
  161 extern bool g_HSEndCharRequired;
  162 extern bool g_HSDetectWhenInsideWord;
  163 extern bool g_HSDoReset;
  164 extern bool g_HSResetUponMouseClick;
  165 extern bool g_HSSameLineAction;
  166 extern TCHAR g_EndChars[HS_MAX_END_CHARS + 1];
  167 
  168 // Global objects:
  169 extern Var *g_ErrorLevel;
  170 extern input_type *g_input;
  171 EXTERN_SCRIPT;
  172 EXTERN_CLIPBOARD;
  173 EXTERN_OSVER;
  174 
  175 extern HICON g_IconSmall;
  176 extern HICON g_IconLarge;
  177 
  178 extern DWORD g_OriginalTimeout;
  179 
  180 EXTERN_G;
  181 extern global_struct g_default, *g_array;
  182 
  183 extern CString g_WorkingDir;
  184 extern LPTSTR g_WorkingDirOrig;
  185 
  186 extern bool g_ContinuationLTrim;
  187 extern bool g_ForceKeybdHook;
  188 extern ToggleValueType g_ForceNumLock;
  189 extern ToggleValueType g_ForceCapsLock;
  190 extern ToggleValueType g_ForceScrollLock;
  191 
  192 extern ToggleValueType g_BlockInputMode;
  193 extern bool g_BlockInput;  // Whether input blocking is currently enabled.
  194 extern bool g_BlockMouseMove; // Whether physical mouse movement is currently blocked via the mouse hook.
  195 
  196 extern Action g_act[];
  197 extern int g_ActionCount;
  198 extern Action g_old_act[];
  199 extern int g_OldActionCount;
  200 
  201 extern key_to_vk_type g_key_to_vk[];
  202 extern key_to_sc_type g_key_to_sc[];
  203 extern int g_key_to_vk_count;
  204 extern int g_key_to_sc_count;
  205 
  206 extern KeyHistoryItem *g_KeyHistory;
  207 extern int g_KeyHistoryNext;
  208 extern DWORD g_HistoryTickNow;
  209 extern DWORD g_HistoryTickPrev;
  210 extern HWND g_HistoryHwndPrev;
  211 extern DWORD g_TimeLastInputPhysical;
  212 extern DWORD g_TimeLastInputKeyboard;
  213 extern DWORD g_TimeLastInputMouse;
  214 
  215 #ifdef ENABLE_KEY_HISTORY_FILE
  216 extern bool g_KeyHistoryToFile;
  217 #endif
  218 
  219 
  220 // 9 might be better than 10 because if the granularity/timer is a little
  221 // off on certain systems, a Sleep(10) might really result in a Sleep(20),
  222 // whereas a Sleep(9) is almost certainly a Sleep(10) on OS's such as
  223 // NT/2k/XP.  UPDATE: Roundoff issues with scripts having
  224 // even multiples of 10 in them, such as "Sleep,300", shouldn't be hurt
  225 // by this because they use GetTickCount() to verify how long the
  226 // sleep duration actually was.  UPDATE again: Decided to go back to 10
  227 // because I'm pretty confident that that always sleeps 10 on NT/2k/XP
  228 // unless the system is under load, in which case any Sleep between 0
  229 // and 20 inclusive seems to sleep for exactly(?) one timeslice.
  230 // A timeslice appears to be 20ms in duration.  Anyway, using 10
  231 // allows "SetKeyDelay, 10" to be really 10 rather than getting
  232 // rounded up to 20 due to doing first a Sleep(10) and then a Sleep(1).
  233 // For now, I'm avoiding using timeBeginPeriod to improve the resolution
  234 // of Sleep() because of possible incompatibilities on some systems,
  235 // and also because it may degrade overall system performance.
  236 // UPDATE: Will get rounded up to 10 anyway by SetTimer().  However,
  237 // future OSs might support timer intervals of less than 10.
  238 #define SLEEP_INTERVAL 10
  239 #define SLEEP_INTERVAL_HALF (int)(SLEEP_INTERVAL / 2)
  240 
  241 enum OurTimers {TIMER_ID_MAIN = MAX_MSGBOXES + 2 // The first timers in the series are used by the MessageBoxes.  Start at +2 to give an extra margin of safety.
  242     , TIMER_ID_UNINTERRUPTIBLE // Obsolete but kept as a a placeholder for backward compatibility, so that this and the other the timer-ID's stay the same, and so that obsolete IDs aren't reused for new things (in case anyone is interfacing these OnMessage() or with external applications).
  243     , TIMER_ID_AUTOEXEC, TIMER_ID_INPUT, TIMER_ID_DEREF, TIMER_ID_REFRESH_INTERRUPTIBILITY};
  244 
  245 // MUST MAKE main timer and uninterruptible timers associated with our main window so that
  246 // MainWindowProc() will be able to process them when it is called by the DispatchMessage()
  247 // of a non-standard message pump such as MessageBox().  In other words, don't let the fact
  248 // that the script is displaying a dialog interfere with the timely receipt and processing
  249 // of the WM_TIMER messages, including those "hidden messages" which cause DefWindowProc()
  250 // (I think) to call the TimerProc() of timers that use that method.
  251 // Realistically, SetTimer() called this way should never fail?  But the event loop can't
  252 // function properly without it, at least when there are suspended subroutines.
  253 // MSDN docs for SetTimer(): "Windows 2000/XP: If uElapse is less than 10,
  254 // the timeout is set to 10." TO GET CONSISTENT RESULTS across all operating systems,
  255 // it may be necessary never to pass an uElapse parameter outside the range USER_TIMER_MINIMUM
  256 // (0xA) to USER_TIMER_MAXIMUM (0x7FFFFFFF).
  257 #define SET_MAIN_TIMER \
  258 if (!g_MainTimerExists)\
  259     g_MainTimerExists = SetTimer(g_hWnd, TIMER_ID_MAIN, SLEEP_INTERVAL, (TIMERPROC)NULL);
  260 // v1.0.39 for above: Apparently, one of the few times SetTimer fails is after the thread has done
  261 // PostQuitMessage. That particular failure was causing an unwanted recursive call to ExitApp(),
  262 // which is why the above no longer calls ExitApp on failure.  Here's the sequence:
  263 // Someone called ExitApp (such as the max-hotkeys-per-interval warning dialog).
  264 // ExitApp() removes the hooks.
  265 // The hook-removal function calls MsgSleep() while waiting for the hook-thread to finish.
  266 // MsgSleep attempts to set the main timer so that it can judge how long to wait.
  267 // The timer fails and calls ExitApp even though a previous call to ExitApp is currently underway.
  268 
  269 // See AutoExecSectionTimeout() for why g->AllowThreadToBeInterrupted is used rather than the other var.
  270 // The below also sets g->ThreadStartTime and g->UninterruptibleDuration.  Notes about this:
  271 // In case the AutoExecute section takes a long time (or never completes), allow interruptions
  272 // such as hotkeys and timed subroutines after a short time. Use g->AllowThreadToBeInterrupted
  273 // vs. g_AllowInterruption in case commands in the AutoExecute section need exclusive use of
  274 // g_AllowInterruption (i.e. they might change its value to false and then back to true,
  275 // which would interfere with our use of that var).
  276 // From MSDN: "When you specify a TimerProc callback function, the default window procedure calls the
  277 // callback function when it processes WM_TIMER. Therefore, you need to dispatch messages in the calling thread,
  278 // even when you use TimerProc instead of processing WM_TIMER."  My: This is why all TimerProc type timers
  279 // should probably have an associated window rather than passing NULL as first param of SetTimer().
  280 //
  281 // UPDATE v1.0.48: g->ThreadStartTime and g->UninterruptibleDuration were added so that IsInterruptible()
  282 // won't make the AutoExec section interruptible prematurely.  In prior versions, KILL_AUTOEXEC_TIMER() did this,
  283 // but with the new IsInterruptible() function, doing it in KILL_AUTOEXEC_TIMER() wouldn't be reliable because
  284 // it might already have been done by IsInterruptible() [or vice versa], which might provide a window of
  285 // opportunity in which any use of Critical by the AutoExec section would be undone by the second timeout.
  286 // More info: Since AutoExecSection() never calls InitNewThread(), it never used to set the uninterruptible
  287 // timer.  Instead, it had its own timer.  But now that IsInterruptible() checks for the timeout of
  288 // "Thread Interrupt", AutoExec might become interruptible prematurely unless it uses the new method below.
  289 #define SET_AUTOEXEC_TIMER(aTimeoutValue) \
  290 {\
  291     g->AllowThreadToBeInterrupted = false;\
  292     g->ThreadStartTime = GetTickCount();\
  293     g->UninterruptibleDuration = aTimeoutValue;\
  294     if (!g_AutoExecTimerExists)\
  295         g_AutoExecTimerExists = SetTimer(g_hWnd, TIMER_ID_AUTOEXEC, aTimeoutValue, AutoExecSectionTimeout);\
  296 } // v1.0.39 for above: Removed the call to ExitApp() upon failure.  See SET_MAIN_TIMER for details.
  297 
  298 #define SET_INPUT_TIMER(aTimeoutValue, aTimeoutAt) \
  299 { \
  300 g_InputTimeoutAt = aTimeoutAt; \
  301 g_InputTimerExists = SetTimer(g_hWnd, TIMER_ID_INPUT, aTimeoutValue, InputTimeout); \
  302 }
  303 
  304 
  305 // For this one, SetTimer() is called unconditionally because our caller wants the timer reset
  306 // (as though it were killed and recreated) unconditionally.  MSDN's comments are a little vague
  307 // about this, but testing shows that calling SetTimer() against an existing timer does completely
  308 // reset it as though it were killed and recreated.  Note also that g_hWnd is used vs. NULL so that
  309 // the timer will fire even when a msg pump other than our own is running, such as that of a MsgBox.
  310 #define SET_DEREF_TIMER(aTimeoutValue) g_DerefTimerExists = SetTimer(g_hWnd, TIMER_ID_DEREF, aTimeoutValue, DerefTimeout);
  311 #define LARGE_DEREF_BUF_SIZE (4*1024*1024)
  312 
  313 #define KILL_MAIN_TIMER \
  314 if (g_MainTimerExists && KillTimer(g_hWnd, TIMER_ID_MAIN))\
  315     g_MainTimerExists = false;
  316 
  317 // See above comment about g->AllowThreadToBeInterrupted.
  318 #define KILL_AUTOEXEC_TIMER \
  319 {\
  320     if (g_AutoExecTimerExists && KillTimer(g_hWnd, TIMER_ID_AUTOEXEC))\
  321         g_AutoExecTimerExists = false;\
  322 }
  323 
  324 #define KILL_INPUT_TIMER \
  325 if (g_InputTimerExists && KillTimer(g_hWnd, TIMER_ID_INPUT))\
  326     g_InputTimerExists = false;
  327 
  328 #define KILL_DEREF_TIMER \
  329 if (g_DerefTimerExists && KillTimer(g_hWnd, TIMER_ID_DEREF))\
  330     g_DerefTimerExists = false;
  331 
  332 #endif