Keyboard macro help requested

Page 1 of 2 12 LastLast

  1. Posts : 843
    11 Pro 21H2 (22000.832)
       #1

    Keyboard macro help requested


    I want to record this exact sequence of keystrokes, and then launch the playback of the sequence with a shortcut with an assigned hotkey combination, making this a one-click operation instead of a 4-key sequence:

    Winkey + b
    menu key (context menu key)
    up arrow key
    Enter

    I have no idea how to do this, and since there's always someone here who knows how to do anything, I thought I'd ask.

    I'd prefer to do it without new software, but if software is indispensable to the task, I'd like it to be portable. But if ...

    Pro 20H2
      My Computers


  2. Posts : 548
    Windows 10 Build 1809
       #2

    Wisewiz said:
    I want to record this exact sequence of keystrokes, and then launch the playback of the sequence with a shortcut with an assigned hotkey combination, making this a one-click operation instead of a 4-key sequence:

    Winkey + b
    menu key (context menu key)
    up arrow key
    Enter

    I have no idea how to do this, and since there's always someone here who knows how to do anything, I thought I'd ask.

    I'd prefer to do it without new software, but if software is indispensable to the task, I'd like it to be portable. But if ...

    Pro 20H2
    Sounds like you could use Autohotkey. I've used it for years for simple repetitive things. It is much more powerful than I can fathom. See AutoHotkey. (It is free or was when I first started with it)
      My Computer


  3. Posts : 843
    11 Pro 21H2 (22000.832)
    Thread Starter
       #3

    Just downloaded the portable 1.33. Looking forward to learning about it. Many thanks.
      My Computers


  4. Posts : 3,274
    Win10
       #4

    Autohotkey is indeed very good at those kinds of macros. Also, sorry for asking, but is it the taskbar settings that you wish to open with that particular combination ? If so, it is possible to create a shortcut on the desktop, using this command as the target, and then setting a hotkey combination for opening it.
    Shortcut Target:

    C:\Windows\explorer.exe ms-settings:taskbar
      My Computers


  5. Posts : 3,274
    Win10
       #5

    Also, just in case you are interested in a completely native solution, the following powershell script can also do the key combinations of:
    WIN + B
    Menu key (context menu key) << substitute Shift+F10
    UP arrow key
    ENTER

    WINTEST.ps1
    Code:
    # see  https://github.com/stefanstranger/PowerShell/blob/master/WinKeys.ps1
     $source = @"
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using System.Runtime.InteropServices;
        using System.Windows.Forms;
        namespace KeyboardSend
        {
            public class KeyboardSend
            {
                [DllImport("user32.dll")]
                public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
                private const int KEYEVENTF_EXTENDEDKEY = 1;
                private const int KEYEVENTF_KEYUP = 2;
                public static void KeyDown(Keys vKey)
                {
                    keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY, 0);
                }
                public static void KeyUp(Keys vKey)
                {
                    keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
                }
            }
        }
    "@
        Add-Type -TypeDefinition $source -ReferencedAssemblies "System.Windows.Forms"
    
        Function Win($Key)
        {
            [KeyboardSend.KeyboardSend]::KeyDown("LWin")
            [KeyboardSend.KeyboardSend]::KeyDown("$Key")
            [KeyboardSend.KeyboardSend]::KeyUp("$Key")
            [KeyboardSend.KeyboardSend]::KeyUp("LWin")
                }
         Win 66
        Start-Sleep -MilliSeconds 150
    [System.Windows.Forms.SendKeys]::SendWait("+{F10}")
    Start-Sleep -MilliSeconds 150
    [System.Windows.Forms.SendKeys]::SendWait("{UP}")
    Start-Sleep -MilliSeconds 150
    [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
    exit
    Again a Shortcut on the desktop with this command as the target (and your own Hotkey setting)
    Code:
    powershell.exe -NoProfile -ExecutionPolicy Bypass -file "C:\Full Path to WINTEST.ps1"
      My Computers


  6. Posts : 843
    11 Pro 21H2 (22000.832)
    Thread Starter
       #6

    Das, my new friend,

    Thank you SO much for doing all that work. That must have taken a whopping chunk out of your day!

    No, I wasn't after the taskbar settings. Here's the situation: I have Malwarebytes Premium, which I run alongside Defender (and they're very happy together, contrary to a lot of trash out there on the Net). I keep the Malwarebytes icon in the leftmost position in the system tray always. The icon has a right-click context menu that has the command Quit Malwarebytes at the bottom, as last entry in that menu. The effect of that command is to kill the Malwarebytes service, which stops MWB completely. The service can't be stopped in services or by batch file command, because it's protected against malware attacks that would seek to disable it. The MWB program itself can stop the service and does, with the Quit command.

    I have written MWB several times, asking them to give me the means to trigger Quit Malwarebytes from the keyboard. So far, the responses I've had have indicated a complete lack of understanding of the simple request. I've even pointed out to them that I can do it from the keyboard with the sequence of strokes in my #1 post (Winkey+b, etc.), but even then they don't seem to understand that they wouldn't be giving away any State Secrets if they gave me a shortcut line to access Quit Malwarebytes.

    (Side note: My mousing has become less and less accurate with advancing years. I have a shaky control of the rodent. My keyboarding, OTOH, hasn't deteriorated.)

    So, the Win+b puts the focus on the target icon, the menu key produces the context menu, the up arrow takes the focus to the bottom line (Quit), and Enter launches the Quit command.

    Your script works perfectly for me the second time I use it. The first run opens the target context menu, but then launches the Notification panel and leaves the context menu open, hidden behind the panel. If I close the panel and then close the context menu by clicking one of the other lines in it (can't click Quit, or there would be no point in running your script again), and then run your script again, it works perfectly: the target menu pops up, the highlight drops to the bottom, and the MWB icon disappears, indicating that the program has terminated and the service is stopped.

    I then load MWB up again, so that the icon is back and the service is running, run your script again, and get the Notification panel. Close that, close the context menu, re-run, and Shazam! Perfect.

    I wouldn't have asked you to do all the work you did on developing that script, and I certainly won't ask you to do any more, but you probably can see why the thing is behaving as it is, and I haven't the shadow of a clue.

    Please don't feel that you need to do any more. You've gone way above and beyond already.
      My Computers


  7. Posts : 3,274
    Win10
       #7

    That's ok, I already had a nearly identical powershell script and it just needed some minor modification.
    Unfortunatley, as I don't use MWB I can't debug the script further on my PC. But, what you can try to do is :

    1 Try to increase the sleep values between the SendKeys commands at those lines to say from 150 to 2500 and then see if that works. If it works, you can reduce that value further and test as necessary.

    2 If that doesn't work, then still with the value set at 2500, maybe try and follow where the highlight is and how it could be changed at any particular point, and then either adjust the [System.Windows.Forms.SendKeys] values or even insert new ones if necessary.

    Change this to test:
    from
    Start-Sleep -MilliSeconds 150
    to
    Start-Sleep -MilliSeconds 2500

    I hope that helps.
      My Computers


  8. Posts : 843
    11 Pro 21H2 (22000.832)
    Thread Starter
       #8

    You're so generous with your time I can't believe it. Good midday to you. I'm just having my first coffee here in Canada, while you're in the lunch zone.

    Last night, I worked over the code a bit, and focused on those times even without knowing what I was doing. I took some programming classes about a century ago, so I'm not quite absolutely terrified when faced with a page of the sort you prepared for me. Unfortunately, my first moves were in what I now know [thanks!] was the wrong direction. I shortened the second and third times and tried that, and then I shortened all three times. The test runs produced the same odd behaviour: wrong outcome on first run; perfect on second. No idea why that would be.

    BTW, the two-run test was just the usual response to finding that something comes very close to working perfectly on the first run: try it again, with the stage set back to pre-test conditions.

    I'm off to play with this remarkable gift of yours now. I'll copy it to the second computer and test it there as well, since the home screen environment is the same on that one, though there are a few differences between the configurations otherwise.

    Thanks again. In the words of The Terminator, "I'll be baaack!"

    Dan
      My Computers


  9. Posts : 3,274
    Win10
       #9

    Have fun !
      My Computers


  10. Posts : 843
    11 Pro 21H2 (22000.832)
    Thread Starter
       #10

    At 2500, 2500, 2500, it works perfectly, but slowly enough so that I can see (1), the focus highlights the correct icon, (2), the context menu opens, (3), the highlight shows up on the Quit MWB line, and (4), the icon disappears. All exactly as desired, but slow. Back to the time-shortening drawing board now.

    D.

    - - - Updated - - -

    It's that middle time (the wait after the +F10 and before the UP) that gums up. I'm not going to bore you to death with the various experiments, but here's where I am now: 10, 200, 100 yields notification panel; 10, 200, 200 NP; 10, 100, 10 NP; 10, 210, 100 Good (!); 10, 210, 10 Good. So 10, 210, 10 seems to be the winner just now.

    I have to go feed the cats and dog. They don't care what I'm doing at the moment.

    Working on it then.
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 11:36.
Find Us




Windows 10 Forums