locked
Send Keys Class codes don't work in Office RRS feed

  • Pregunta

  • The shortcut on the keyboard for Home/ End is Crtl + Home/ End in Office but how is the shortcut for horizontal scrolling that i can use it as Send Key class code?




    • Editado ILT5000 sábado, 1 de agosto de 2020 19:54
    sábado, 1 de agosto de 2020 19:52

Todas las respuestas

  • I found the shortcut over AHK. It's scroll lock on, left/right, scroll lock off.

    But that let the LED for the scroll lock turn on and off on the keyboard everytime. Also it works in Excel and OneNote but not in Word.

    How does Microsoft implements it that i can scroll horizontal by left/right clicking the scroll wheel with the default settings in Word and OneNote?






    • Editado ILT5000 domingo, 2 de agosto de 2020 10:10
    domingo, 2 de agosto de 2020 10:06
  • Beginners often think that sending keys are the simplest way to solve problems but then they have problems implementing that. It might be possible to solve the fundamental problem by sending keys but there is likely a simpler solution that initially looks harder. Unfortunately you have not described the fundamental problem.


    Sam Hobbs
    SimpleSamples.Info

    domingo, 2 de agosto de 2020 17:46
  • Hi ILT5000,
    As you said, you can use AutoHotKey (AHK) to achieve horizontal scrolling in Excle, OneNote except Word.
    Regarding implementation in Word, you can try the following suggestions:
    1. First, you can use AutoHotKey to send custom keystrokes to Word in response to mouse operations.
    2. Then set Word key binding.
    3. Finally, define the Word macro in the "normal" template.
    More details you can refer to  iagrapefruit's answer.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    lunes, 3 de agosto de 2020 3:02
  • Hi ILT5000,
    Has your problem been solved? If it is resolved, we suggest that you mark it as the answer. So it can help other people who have the same problem find a solution quickly.
    Best Regards,
    Daniel Zhang


    "Windows Forms General" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Windows Forms General" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    miércoles, 12 de agosto de 2020 9:26
  • I try to implement it with c#. 

    I want the horizontally scrolling when i scroll up and down.

    Now i try it with SendMessage as follows but nothing happens. I just want to simulate the default function of the middle key tilting (mouse wheel left/right clicking == 0x20e) which scrolls horizontally.

    1. Get the handle of the active application:

    [DllImport("user32.dll")]
    private static extern IntPtr GetForegroundWindow();
    
    public IntPtr GetActiveWindow()
    {
        try
        {
            const int nChars = 256;
            IntPtr handle;
            StringBuilder Buff = new StringBuilder(nChars);
            handle = GetForegroundWindow();
    
            return handle;
        }
        catch
        {
            return IntPtr.Zero;
        }
    }

    2. SendMessage method:

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

    3. When i scroll up:

    if (e.Delta > 0)
    {
        int direction = 120;
    
        e.Handled = true;
        
        SendMessage(GetActiveWindow(), 0x20E, (IntPtr) direction, IntPtr.Zero);
    
    }

    I found a lot of examples but nothing works. Maybe there's something wrong with the handle value or the SendMessage parameters ?!. I also couldn't find the spy++ in Visual Studio 2019 Community for checking the lparam or the parameters in general.

    I tried the SendInput method until i saw that it's propably not the right solution because of several reasons.




    • Editado ILT5000 domingo, 16 de agosto de 2020 1:43
    domingo, 16 de agosto de 2020 0:56
  • The following shows the Tools menu for me using VS 2017. Note the Spy++.

    Also note that it helps to use something to give names to window messages. For one thing it helps others help you instead of requiring them to look up what 0x20E is.



    Sam Hobbs
    SimpleSamples.Info


    domingo, 16 de agosto de 2020 4:44
  • I don't have it in VS. I downloaded it on Github (exe and dll).

    Would be great to know if it works with 0x20e (horizontally scrolling) but it works as follows:

    SendMessage(GetForegroundWindow(), WM_HSCROLL, (IntPtr)SB_PAGEDOWN, IntPtr.Zero); 

    Problem here, GetForegroundWindow() only works with Chrome and Edge, not with any other application. Isn't it the window handle ? (Documentation said window handle?!)

    Spy++ shows a totally different handle code which i can't use for testing because it looks like this: 000D0994 (Can only store it as string, no converting to intPtr).

    It's all so confusing.

    Now i've recognized that i don't need the active window rather the window below the mouse pointer.

    Somebody suggested to use the FindWindow() method for finding the right window handle. Tried a bit but i can't get it working. :(



    • Editado ILT5000 domingo, 16 de agosto de 2020 21:48
    domingo, 16 de agosto de 2020 21:46
  • Problem here, GetForegroundWindow() only works with Chrome and Edge, not with any other application. Isn't it the window handle ? (Documentation said window handle?!)

    GetForegroundWindow will do what it is designed to do with all applications but it usually cannot be used to do anything for any browser, including Chrome and Edge. In other words it gets a window's handle for other applications but I would not expect the handle to help with Chrome and Edge. However you are confusing me since Office does not use Chrome or Edge.

    Spy++ shows a totally different handle code which i can't use for testing because it looks like this: 000D0994 (Can only store it as string, no converting to intPtr).

    000D0994 is a hexadecimal number. So prefix it with ox, as in 0x000D0994 (the only letters there are D and x).



    Sam Hobbs
    SimpleSamples.Info

    domingo, 16 de agosto de 2020 23:50
  • Current situation is that i got it working with WindowFromPoint for all tested applications except Office.

    I checked the handles with SPY++ and it works, if i take the found handle of Chrome.

    Why is it not working with the Word handles, shouldn't it?

    Structure looks a little bit as follows, it's very branched:

    - Window xxx "Dokument1 - Word" OpusApp
    - xxx
    - xxx
         - xxx
         - xxx 
              -Window xxx "Horizontal" NUIScrollbar

    (I checked them all in my code. Not allowed to upload the image here.)

    Sadly i can't log messages with SPY++ in several application like Office and Chrome with the Finder. It works in IE. As suggested it also doesn't work, if i start and stop the logging. Nothing appears. The "All Windows in System" option works but i can't figure it out what i have to filter. Nothing when i search for "Scroll" etc.

    Would it make a difference if i use mouse_event/SendInput? (I tried to implement it but it always let my VS crash.)





    • Editado ILT5000 sábado, 22 de agosto de 2020 18:06
    sábado, 22 de agosto de 2020 17:46
  • Hi ILT5000,
    You need to note that Spy++ needs to inject a hook to monitor window messages. For this to work, the bitness of the hook function needs to match the bitness of the process owning the window.
    And therefore you should use the 32-bit version of Spy++ to monitor windows of 32-bit apps, and the 64-bit version to monitor 64-bit apps.
    More details you can refer to this document.
    Best Regards,
    Daniel Zhang


    "Windows Forms General" forum will be migrating to a new home on Microsoft Q&A (Preview)!
    We invite you to post new questions in the "Windows Forms General" forum’s new home on Microsoft Q&A (Preview)!
    For more information, please refer to the sticky post.

    miércoles, 26 de agosto de 2020 2:31