Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Hotkey For Refactor Sometimes Not Working #3996

Closed
spinjector opened this issue May 7, 2018 · 6 comments
Closed

Hotkey For Refactor Sometimes Not Working #3996

spinjector opened this issue May 7, 2018 · 6 comments
Labels
bug Identifies work items for known bugs feature-hotkeys heisenbug A bug that defies a clean reproduction, making it very hard to fix.

Comments

@spinjector
Copy link

Version 2.2.6693.19208
OS: Microsoft Windows NT 6.1.7601 Service Pack 1, x64
Host Product: 2007 Microsoft Office system x86
Host Version: 12.0.6735.5000
Host Executable: MSACCESS.EXE

version info VBA IDE:
Microsoft Visual Basic 6.5
Version 1057
VBA: Retail 6.5.1057
Forms3: 12.0.6723.500 <--- other digit(s) possibly truncated by edge of dialog

I started using RD for the first time last week. I'm having a frequent issue where the hotkey for Refactor doesn't work. Details are as follows...

I'm in a code module by any means, such as Alt+Tab, opening an XLS or ACCDB and then a code module, or I'm already in VBA and double-click a module in Project Explorer. Then I work on the code. I press the hotkey for Code Explorer...and nothing happens. Sometimes if I Sync the Code Explorer it helps, but this is rare.

If I use the RD menu to access the Refactor dialog, this fixes the Hotkey for a while, but it always breaks again. That would be Menu> Rubberduck > Refactor > Rename, possibly a Resync first if it's grayed out. What's done on the dialog doesn't matter, it can either be canceled or used to rename something. Either way the result is the same; the Hotkey starts working. But only for a while; eventually it breaks again.

I don't know what the troubleshooting tricks for RD are, but here's what I've done:

  1. Disabled another add-in called PrettyCodePrint, the only other add-in which I use.
  2. Changed the Refactor hotkey to other values, such as Shift+Ctrl+Alt+X.
  3. Rebooted.
  4. Tried other XLS and ACCDB files. The issue occurs in both Excel and Access.

Note: I haven't yet tried to reinstall anything such as Office 2007, since this is my primary code/hacking machine and I would rather not have to recreate the environment.

@spinjector
Copy link
Author

Some additional info to add. I changed the Hotkey character assignment back to its default Ctrl+Shift+R, but somewhere along the way my fingers got confused, and numerous times over the past hour I've hit Ctrl+Shift+T by accident...and that DOES work. But if I immediately press Ctrl+Shift+R, nothing happens. So it seems the "listener" for RD hotkeys is working...almost. It likes Ctrl+Shift+T, but not Ctrl+Shift+R. Also, Ctrl+Shift+` (Refresh) works too. I'd test some of the others, but I don't know what the other functions do yet. Still a Noob. =-)

@retailcoder retailcoder added bug Identifies work items for known bugs feature-hotkeys labels May 7, 2018
@retailcoder
Copy link
Member

The VBIDE API doesn't provide any infrastructure for hotkeys, so we (people building VBIDE add-ins) need to roll our own - we basically subclass the VBE's MainWindow and handle WM_Hotkey messages (which works because we register them with User32.RegisterHotkey), however because these messages are system-wide, we need to "detach" the hooks and "re-attach" them when the VBE loses/gets focus.

Whenever RD hotkeys aren't responding, a work-around would be to activate some code pane, or otherwise force the VBE to handle a SETFOCUS message:

    public override int SubClassProc(IntPtr hWnd, IntPtr msg, IntPtr wParam, IntPtr lParam, IntPtr uIdSubclass, IntPtr dwRefData)
    {
        var suppress = false;
        switch ((WM)msg)
        {
            case WM.HOTKEY:
                suppress = hWnd == Hwnd && HandleHotkeyMessage(wParam);
                break;
            case WM.SETFOCUS:
                Attach();
                break;
            case WM.RUBBERDUCK_CHILD_FOCUS:
                if (lParam == IntPtr.Zero)
                {
                    Detach();
                }
                else
                {
                    Attach();
                }
                suppress = true;
                break;
            case WM.NCACTIVATE:
                if (wParam == IntPtr.Zero)
                {
                    Detach();
                }
                break;
            ...

Not sure how to fix this reliably.

@bclothier
Copy link
Contributor

bclothier commented May 8, 2018

Instead of fixing this, we can consider using a different approach suggested by @WaynePhillipsEA -- using SetWindowsHookEx API. That would eliminate the need to attach & detach on focus change and if we opt to hook to the low level keyboard state, that would allow for two step shortcuts.

@Vogel612
Copy link
Member

Vogel612 commented May 8, 2018

@bclothier if we don't have an issue open for that, I'd recommend moving that to a separate [technical-debt]/[enhancement] issue, to enable discussing that without derailing this issue

@comintern
Copy link
Contributor

Linking chat, might be relevant.

@Vogel612 Vogel612 added the hacktoberfest Tags issues for Hacktoberfest 2019 label Sep 20, 2019
@bclothier bclothier removed the hacktoberfest Tags issues for Hacktoberfest 2019 label Nov 5, 2019
@retailcoder retailcoder added the heisenbug A bug that defies a clean reproduction, making it very hard to fix. label Feb 1, 2025
@retailcoder
Copy link
Member

Closing in favor of #6245

@retailcoder retailcoder closed this as not planned Won't fix, can't repro, duplicate, stale Feb 2, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Identifies work items for known bugs feature-hotkeys heisenbug A bug that defies a clean reproduction, making it very hard to fix.
Projects
None yet
Development

No branches or pull requests

5 participants