I'm not sure if this is possible, but I've seen a LOT of people get confused by the stuck-Alt-key issue and complain in the Starter Pack thread.
Are you sure this is caused by DFHack? I know it's noticeable with DFHack keybindings, but could you see if it occurs with vanilla DF?
I'm reasonably certain this problem is specific to DFHack keybindings on Windows. While the Alt key is stuck, DFHack (a) incorrectly runs hotkeys defined with Alt, and (b) incorrectly fails to run hotkeys defined without Alt. But only DFHack keybindings are affected; not native DF keys, and not keys checked by DFHack plugins.
I have been able to modify Core::DFH_SDL_EVENT to notice SDL window focus events on Linux, which would be a convenient place to clear the bad state if we can do so. Unfortunately, ke->ksym.mod is set by SDL internally, so we would need to either maintain our own flag for the Alt key, or perhaps use SDL_PushEvent to pretend that the Alt key has been pressed and released. Note that DF itself uses the former solution; see update_modstate in g_src/enabler_input.cpp, and its associated comment.
Unfortunately, while I sometimes play on Windows, I can't currently compile for that platform, which makes it hard to test potential solutions.