MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / ExpandEventArray

Function ExpandEventArray

source/keyboard_mouse.cpp:2688–2716  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2686
2687
2688ResultType ExpandEventArray()
2689// Returns OK or FAIL.
2690{
2691 if (sAbortArraySend) // A prior call failed (might be impossible). Avoid malloc() in this case.
2692 return FAIL;
2693 #define EVENT_EXPANSION_MULTIPLIER 2 // Should be very rare for array to need to expand more than a few times.
2694 size_t event_size = (sSendMode == SM_INPUT) ? sizeof(INPUT) : sizeof(PlaybackEvent);
2695 void *new_mem;
2696 // SendInput() appears to be limited to 5000 chars (10000 events in array), at least on XP. This is
2697 // either an undocumented SendInput limit or perhaps it's due to the system setting that determines
2698 // how many messages can get backlogged in each thread's msg queue before some start to get dropped.
2699 // Note that SendInput()'s return value always seems to indicate that all the characters were sent
2700 // even when the ones beyond the limit were clearly never received by the target window.
2701 // In any case, it seems best not to restrict to 5000 here in case the limit can vary for any reason.
2702 // The 5000 limit is documented in the help file.
2703 if ( !(new_mem = malloc(EVENT_EXPANSION_MULTIPLIER * sMaxEvents * event_size)) )
2704 {
2705 sAbortArraySend = true; // Usually better to send nothing rather than partial.
2706 // Leave sEventSI and sMaxEvents in their current valid state, to be freed by CleanupEventArray().
2707 return FAIL;
2708 }
2709 else // Copy old array into new memory area (note that sEventSI and sEventPB are different views of the same variable).
2710 memcpy(new_mem, sEventSI, sEventCount * event_size);
2711 if (sMaxEvents > (sSendMode == SM_INPUT ? MAX_INITIAL_EVENTS_SI : MAX_INITIAL_EVENTS_PB))
2712 free(sEventSI); // Previous block was malloc'd vs. _alloc'd, so free it.
2713 sEventSI = (LPINPUT)new_mem; // Note that sEventSI and sEventPB are different views of the same variable.
2714 sMaxEvents *= EVENT_EXPANSION_MULTIPLIER;
2715 return OK;
2716}
2717
2718
2719

Callers 2

PutKeybdEventIntoArrayFunction · 0.85
PutMouseEventIntoArrayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected