Jump to content
Macro Express Forums

acantor

Members
  • Content Count

    937
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by acantor

  1. THE CHALLENGE The challenge is to create a set of hotkeys for the Macro Express Script Editor that insert the instructions you use most often without the need to touch the mouse. For example: - Press a hotkey to insert the "Text Type" command - Press another hotkey to insert the "Mouse Left Click" command - Press a third hotkey to insert the "Repeat Start" command SUGGESTED REQUIREMENTS 1. Solutions for Windows 7 and 10 may be different. So make your hotkeys function in whatever operating system you currently use. 2. The hotkeys work in all Script Editor panels: In other words, if you press a hotkey while the "Activations" (or "Variables" or "Scope"…) panel has focus, the macro inserts the instruction in the "Script" panel. 3. The hotkeys work regardless of the size and position of the Script Editor window. 4. The hotkeys work regardless of display resolution settings, custom scaling settings, etc. For example, if you change the resolution from [1,920 x 1080] to [800 x 600] pixels, your hotkeys still work. BACKGROUND There are dozens of built-in hotkeys in the Macro Express Script Editor, including: Alt + I = Open "Script" panel Alt + Down arrow = Go to the "Search for Command" text box Alt + Left arrow = Go to left pane Alt + Right arrow = Go to right pane Ctrl + D = Duplicate selected command(s) Ctrl + N = Enable / Disable the selected line(s) of code ALTERNATIVE APPROACHES This challenge is, above all, a practical exercise. After I defined 13 hotkeys for the Script Editor, the time I spent developing MEP scripts dropped in half. I prefer hotkeys over the Macro Express "Favorites" and "Snippets" features, but I acknowledge the hotkey approach may not jive well for others! Nevertheless, I hope you find this an interesting Macro Express problem with wide applicability. By the way, some of my hotkeys DON’T insert a Macro Express instruction. Instead, they give focus to groups of related commands. For example, there are 17 items in the "Mouse" group in the left pane. When I press my hotkey, the 5th item in the "Mouse" group ("Mouse Left Click") gains focus. Then I select the mouse command I want by pressing up and down arrow keys, and insert it by pressing Enter. This challenge may seem easy, but when I tried, I had to put in time before I got consistent and reliable results.
  2. There is a good reason to capture scripts via Macro Express: it's a way to become familiar with a limited number of Macro Express instructions. But often, the resulting scripts have limited practical value. The scripts tend to fail, sometimes spectacularly. Given your struggles, maybe it's time to move on from recording (inherently unreliable) scripts to developing scripts that reliably perform simple tasks by sending keystrokes, moving the mouse pointer, and clicking. For a beginner, there may be a learning curve to figure out how to make these scripts work every time and in every context, but it's time well spent. Decide on a task to perform. Create the first line in Macro Express. Test. If it works, add the second line of instructions. Test. And so on.
  3. The problem you are experiencing may relate to your Macro Express settings. In the Macro Express Explorer, choose Options > Preferences... > General > Capture, and make sure keystrokes and mouse actions are set properly.
  4. You're right, rberq, it took digging before I stumbled upon Shift + Ctrl + equal sign. As a (mostly) non-mouse user, I already knew Home (go to start of row) and Shift + spacebar (select row). Edited: Only today did I abandon the quest to come up with a satisfactory solution for moving columns. The task requires the insertion point to jump to the topmost cell in a column. I have not yet discovered a way to do this via keyboard that works in every Excel worksheet. My solution sometimes fails.
  5. Here are my scripts for moving an entire Excel row down and up, without the need to select the row. The row that is moved is always the one that has keyboard focus. Each script is only five lines long. I tested a version that combined all five lines into a single "Text Type" instruction. It worked. But the challenge wasn’t to create a solution with the fewest lines of code. It’s much clearer when broken up this way: Move row down: Text Type (Simulate Keystrokes): <HOME> // Must start selection from Column A Text Type (Simulate Keystrokes): <SHIFT><SPACE> // Select the row Text Type (Simulate Keystrokes): <CONTROL>x Text Type (Simulate Keystrokes): <ARROW DOWN><ARROW DOWN> Text Type (Simulate Keystrokes): <SHIFT><CONTROL>= // Insert a row <TEXT TYPE Action="0" Text="<HOME>" _COMMENT="Must start selection from Column A "/> <TEXT TYPE Action="0" Text="<SHIFT><SPACE>" _COMMENT="Select the row"/> <TEXT TYPE Action="0" Text="<CONTROL>x"/> <TEXT TYPE Action="0" Text="<ARROW DOWN><ARROW DOWN>"/> <TEXT TYPE Action="0" Text="<SHIFT><CONTROL>=" _COMMENT="Insert a row"/> Move row up: Text Type (Simulate Keystrokes): <HOME> // Must start selection from Column A Text Type (Simulate Keystrokes): <SHIFT><SPACE> // Select the row Text Type (Simulate Keystrokes): <CONTROL>x Text Type (Simulate Keystrokes): <ARROW UP> Text Type (Simulate Keystrokes): <SHIFT><CONTROL>= // Insert a row <TEXT TYPE Action="0" Text="<HOME>" _COMMENT="Must start selection from Column A "/> <TEXT TYPE Action="0" Text="<SHIFT><SPACE>" _COMMENT="Select the row"/> <TEXT TYPE Action="0" Text="<CONTROL>x"/> <TEXT TYPE Action="0" Text="<ARROW UP>"/> <TEXT TYPE Action="0" Text="<SHIFT><CONTROL>=" _COMMENT="Insert a row"/> If you want to try these scripts, set scope to window-specific. Depending on the version of Excel you are using, you will either need to specify a partial match to: "Excel -" or "- Excel" Check the title bar in Excel to discover whether the hyphen goes before or after the word "Excel." The hotkeys I chose for these scripts are Alt + Shift + down arrow (to move the row down), and Alt + Shift + up arrow (to move the row up). I opted for these hotkeys because they parallel the hotkeys available by default in Word, Outlook, and PowerPoint. But of course you can choose any activation you like.
  6. The challenge was to create two Macro Express scripts: one to move the current paragraph up, and the other to move the current paragraph down, without the need to (manually) select any text. The inspiration for the challenge is Alt + Shift + up and down arrows in Word, which move the current paragraph without selecting it. (These built-in commands don't use the clipboard, but the Macro Express scripts likely will.) Anyone want to give this challenge a shot for Excel? The task is to create two hotkeys that move the current ROW up or down. I'll post a solution soon.
  7. What prefix are you using? Test your macros with a different prefix, preferably one-character long instead of the two-character default "##", e.g.,: Q , / or something similar. What applications are your macros failing in? Is the scope of these macros global or window/program specific? Do the macros fail if you add a hotkey activation?
  8. Cory, thank you for pointing out a tremendously useful Macro Express instruction. I wasn't aware of it.
  9. Yep, you got it, Ctrl + Down and Ctrl + Up. So the keyboard shortcuts are similar to the similar Office commands (Shift + Ctrl + Down and Shift + Ctrl + Up). The keyboard shortcuts for Duplicate Command (Ctrl + D) and Comment (Ctrl + Alt + C) are listed in the "Edit" menu of the Script Editor. Too bad "Comment" cannot be Ctrl + C because that's the standard Windows keyboard shortcut for Copy to the clipboard. (On the other hand, if someone needs to sprinkle comments in their scripts more than they need to copy lines to the clipboard, they can create a window-specific Macro Express script triggered by Ctrl + C, that outputs Ctrl + Alt + C... Text Type (Simulate Keystrokes): <CONTROL><ALT>c As you observed, pressing Ctrl + X causes selected line(s) to vanish, but that's because the information is "Cut." This keyboard shortcut works almost everywhere in Windows. The cut text resides in the clipboard and is available for pasting.
  10. Here is a challenge within the challenge. In the Macro Express Script Editor, there are two icons at the top of the vertical bar that runs along the right side of the screen. Click the top icon to move the current line upwards (without selecting it), and the icon beneath it to move the current line down. If more than one line is selected, the icons act on the entire block of lines rather than one line. These two commands parallel the paragraph-moving functionality in Word, PowerPoint, and Outlook. And like the Office commands, the Macro Express commands don't use the clipboard. It turns out that there are keyboard equivalents in the Script Editor for performing these tasks. They appear to be undocumented. (At least, I couldn't find them... I discovered the keyboard shortcuts by accident.) Through trial-and-error experimentation, can you figure out the two built-in keyboard shortcuts for moving text within the Script Editor? And while you are at it, figure out the built-in keyboard shortcuts for the third and fourth icons, i.e., duplicate line (or several selected lines), and add a comment? (Hint: These two shortcuts are documented.)
  11. Your finding is surprising, but you're right. I'm sure this was not the case in earlier versions of Word. (I'm using Word 2019). So the instruction now works in Word, although not everywhere in Word. 1. In a document: yes. 2. In the ribbons, yes if the item is a field where the user can type (e.g., Home --> Font name drop-down, or to its right, the Font Size drop-down). 3. But apparently not when the focused item in a Ribbon is a button or similar control (e.g., Home --> Bold, Italics, etc.) 4. In dialog boxes and panels: Same as 2 and 3 above.
  12. That's right. Macro Express must be running. You can set Macro Express to start automatically whenever your computer starts: From the Macro Express Explorer: Options Preferences... Startup Windows Startup Run when Windows starts up [check]
  13. Date/Time: Type out the current date/time using "d mmmm yyyy" as the format I use "d mmmm yyyy" format for my macro, but it can be changed to whatever format suits you.
  14. I'm wondering whether your macro for moving paragraphs in Notepad would be amenable to routing the mouse cursor to the text cursor position. I don't remember whether the instruction works in Notepad. I know it DOES NOT work in Word or any browser I've tested it with.
  15. Ha! Google's speech recognition products handle mumbling better than Dragon. On many measures of the usefulness of speech recognition, Google has surpassed Dragon. Since you're an Android user, take a glimpse of the future of speech recognition technology by downloading Google's "Live Transcribe" free app. Nevertheless, Dragon is a remarkable product because of its versatility. It can be used to dictate text, revise text, control a small number of applications, and more -- hands-free. Dragon is most accurate when users speak in long, unbroken utterances (eight or more words without pausing), clearly spoken. No guarantees when mumbling!
  16. But until that future day, there is something that can be done now that is a step in that direction. Use Dragon software, which is third-party speech recognition software for Windows. When Dragon is running on a system, voice-enabling Macro Express scripts is fairly straightforward. (It's less easy with the inexpensive "Home" edition than the Professional editions, but still do-able.) So instead of triggering a script with your thoughts, at least you can trigger a script by saying a few syllables.
  17. Sometimes it's possible to take advantage of the "Mouse Move to the Text Cursor Position" in applications that don't support the command. For example, in some programs, the command moves the mouse cursor to the upper left corner of the active window rather than to the text cursor position. But if clicking in that corner resets the tab order, then that's a useful navigation technique... something like this: Mouse Move: To the Text Cursor Position // Jump the mouse cursor to the upper-left corner of the active window Mouse Left Click // Clicking here resets the tab order Repeat Start (Repeat 18 times) // Navigate to the "Surname" field Text Type (Simulate Keystrokes): <TAB> End Repeat Text Type (Simulate Keystrokes): %Surname%
  18. Once I worked out a reliable way to select the current paragraph (i.e., the paragraph that contains the insertion point/text cursor), I realized I could ditch variables and string operations. So for moving paragraphs up and down in plain text Outlook messages, these two macros function very much like the commands already available in HTML and RTF messages. (The built in commands don't involve the clipboard, but these commands do.) For both command, set the scope to window, partial match, "- Message (Plain Text)" Like the built-in commands for HTML and RTF messages, I use Alt + Shift + down and Alt + Shift + up as hotkeys. Down: Mouse Move: To the Text Cursor Position // Route the mouse pointer to the insertion point Mouse Left Click // Triple click to select the paragraph Mouse Left Click Mouse Left Click Text Type (Simulate Keystrokes): <CONTROL>x Text Type (Simulate Keystrokes): <CONTROL><ARROW DOWN> // Select down one paragraph Text Type (Simulate Keystrokes): <CONTROL>v Text Type (Simulate Keystrokes): <ENTER> Text Type (Simulate Keystrokes): <SHIFT><CONTROL><ARROW UP> // Reselect the originally selected paragraph <MOUSE MOVE Option="\x00" X="0" Y="0" _PROMPT="0x000A" _COMMENT="Route the mouse pointer to the insertion point"/> <MOUSE LEFT CLICK _COMMENT="Triple click to select the paragraph"/> <MOUSE LEFT CLICK/> <MOUSE LEFT CLICK/> <TEXT TYPE Action="0" Text="<CONTROL>x"/> <TEXT TYPE Action="0" Text="<CONTROL><ARROW DOWN>" _COMMENT="Select down one paragraph"/> <TEXT TYPE Action="0" Text="<CONTROL>v"/> <TEXT TYPE Action="0" Text="<ENTER>"/> <TEXT TYPE Action="0" Text="<SHIFT><CONTROL><ARROW UP>" _COMMENT="Reselect the originally selected paragraph"/> Up: Mouse Move: To the Text Cursor Position // Route the mouse pointer to the insertion point Mouse Left Click // Triple click to select the paragraph Mouse Left Click Mouse Left Click Text Type (Simulate Keystrokes): <CONTROL>x Text Type (Simulate Keystrokes): <CONTROL><ARROW UP> // Select up one paragraph Text Type (Simulate Keystrokes): <CONTROL>v Text Type (Simulate Keystrokes): <ENTER> Text Type (Simulate Keystrokes): <SHIFT><CONTROL><ARROW UP> // Reselect the originally selected paragraph <MOUSE MOVE Option="\x00" X="0" Y="0" _PROMPT="0x000A" _COMMENT="Route the mouse pointer to the insertion point"/> <MOUSE LEFT CLICK _COMMENT="Triple click to select the paragraph"/> <MOUSE LEFT CLICK/> <MOUSE LEFT CLICK/> <TEXT TYPE Action="0" Text="<CONTROL>x"/> <TEXT TYPE Action="0" Text="<CONTROL><ARROW UP>" _COMMENT="Select up one paragraph"/> <TEXT TYPE Action="0" Text="<CONTROL>v"/> <TEXT TYPE Action="0" Text="<ENTER>"/> <TEXT TYPE Action="0" Text="<SHIFT><CONTROL><ARROW UP>" _COMMENT="Reselect the originally selected paragraph"/>
  19. Here is a "move paragraph down" command for Outlook plain text messages. It's not 100% yet, but close. I also have a move paragraph up command, but when I apply the same logic the macro is still doing a few odd things. (I'll post it when I've got it working better.) I'm using the "Mouse Move: To the Text Cursor Position" instruction. The instruction fails in many programs, but works reliably in this context. After moving the mouse pointer to the cursor, the command triple clicks, which selects the entire paragraph. Then the macro sends keystrokes to extend the selection to the end of the following paragraph. The text is copied, assigned to a variable, split on the carriage return, and outputted in reverse order. If you want to try it, set the scope to window, partial match, "- Message (Plain Text)" Mouse Move: To the Text Cursor Position // Route the mouse pointer to the insertion point Mouse Left Click // Triple click to select the paragraph Mouse Left Click Mouse Left Click Text Type (Simulate Keystrokes): <CONTROL><SHIFT><ARROW DOWN> // Extend the selection to include the following paragraph Text Type (Simulate Keystrokes): <CONTROL>c Variable Set String %Clip% from the clipboard contents Split String "%Clip%" on "%CR%" into %Paragraph%, starting at 1 // Split the two paragraphs at the Carriage Return Text Type (Use Clipboard and Paste Text): %Paragraph[2]% %Paragraph[1]% Text Type (Simulate Keystrokes): <SHIFT><CONTROL><ARROW UP> // Reselect the paragraph that was selected first <MOUSE MOVE Option="\x00" X="0" Y="0" _PROMPT="0x000A" _COMMENT="Route the mouse pointer to the insertion point"/> <MOUSE LEFT CLICK _COMMENT="Triple click to select the paragraph"/> <MOUSE LEFT CLICK/> <MOUSE LEFT CLICK/> <TEXT TYPE Action="0" Text="<CONTROL><SHIFT><ARROW DOWN>" _COMMENT="Extend the selection to include the following paragraph"/> <TEXT TYPE Action="0" Text="<CONTROL>c"/> <VARIABLE SET STRING Option="\x02" Destination="%Clip%" NoEmbeddedVars="FALSE"/> <SPLIT STRING Source="%Clip%" SplitChar="%CR%" Dest="%Paragraph%" Index="1" _COMMENT="Split the two paragraphs at the Carriage Return"/> <TEXT TYPE Action="1" Text="%Paragraph[2]%\r\n%Paragraph[1]%"/> <TEXT TYPE Action="0" Text="<SHIFT><CONTROL><ARROW UP>" _COMMENT="Reselect the paragraph that was selected first"/>
  20. I hope you will share the latest version! I thought that I had found a reliable method to select two paragraphs in Outlook plain text messages by sending keystrokes, but I may have hit a brick wall. I haven't given up on the approach yet!
  21. My approach for Notepad (which swaps lines, not paragraphs; and only works if text wrap is toggled off) is entirely different. My two scripts output keystrokes for moving a line down or up. The macros mimic the behaviour of the Word commands that inspired this challenge by selecting the most recently moved text. My scripts fail occasionally, probably due to timing issues. But I find them reliable enough to use when I am editing HTML files. // Swap the current line with the line that's below it Text Type (Simulate Keystrokes): <END><SHIFT><HOME> // Select current line, from end to start Text Type (Simulate Keystrokes): <SHIFT><ARROW LEFT> // Extend the selection by one character to the left Text Type (Simulate Keystrokes): <CONTROL>x Text Type (Simulate Keystrokes): <ARROW DOWN><END> // Move down one line, go to end of it Text Type (Simulate Keystrokes): <CONTROL>v Text Type (Simulate Keystrokes): <SHIFT><HOME> // Re-select the line <COMMENT Value="Swap the current line with the line that's below it"/> <TEXT TYPE Action="0" Text="<END><SHIFT><HOME>" _COMMENT="Select current line, from end to start"/> <TEXT TYPE Action="0" Text="<SHIFT><ARROW LEFT>" _COMMENT="Extend the selection by one character to the left"/> <TEXT TYPE Action="0" Text="<CONTROL>x"/> <TEXT TYPE Action="0" Text="<ARROW DOWN><END>" _COMMENT="Move down one line, go to end of it"/> <TEXT TYPE Action="0" Text="<CONTROL>v"/> <TEXT TYPE Action="0" Text="<SHIFT><HOME>" _COMMENT="Re-select the line"/> // Swap the current line with the line that's above it Text Type (Simulate Keystrokes): <HOME><SHIFT><END> // Select current line, from start to end Text Type (Simulate Keystrokes): <SHIFT><ARROW RIGHT> // Extend the selection by one character to the right Text Type (Simulate Keystrokes): <CONTROL>x Text Type (Simulate Keystrokes): <ARROW UP><HOME> // Move up one line, go to start of line (just in case) Text Type (Simulate Keystrokes): <CONTROL>v Text Type (Simulate Keystrokes): <SHIFT><ARROW UP> // Re-select the line <COMMENT Value="Swap the current line with the line that's above it"/> <TEXT TYPE Action="0" Text="<HOME><SHIFT><END>" _COMMENT="Select current line, from start to end"/> <TEXT TYPE Action="0" Text="<SHIFT><ARROW RIGHT>" _COMMENT="Extend the selection by one character to the right"/> <TEXT TYPE Action="0" Text="<CONTROL>x"/> <TEXT TYPE Action="0" Text="<ARROW UP><HOME>" _COMMENT="Move up one line, go to start of line (just in case)"/> <TEXT TYPE Action="0" Text="<CONTROL>v"/> <TEXT TYPE Action="0" Text="<SHIFT><ARROW UP>" _COMMENT="Re-select the line"/> I'm working on versions of these commands for Outlook Plain Text messages. (The functionality for moving paragraphs up and down is built in for HTML and Rich Text messages, but not for Plain Text messages.) I initially tried to send keystrokes like my Notepad scripts, but the scripts got way too complex when I began uncovering one borderline situation after another, e.g., blank lines between paragraphs vs. none; first or last paragraph in the email message, etc. So I (mostly) ditched keystrokes, and did something similar to you. My new version selects and copies two paragraphs, transfers the text to a variable, splits the string on the CRLF, and outputs the two paragraphs in reverse order. Hopefully I'll iron out the kinks soon. If I can't, I might borrow from your playbook and process the entire document in Variable Land!
  22. In VBA (the underlying macro language for Word), in addition to being able to act on the contents of the clipboard, one can also act on the contents of the selection: the data that has been selected in a Word document. The selection can be text, formatting information, images, or, when nothing is selected, the text cursor itself. The selection is not so much a clipboard equivalent, but an entirely different way to handle data. Because we don't have direct, programmatic access to the selection via Macro Express, we can have challenges like this...
  23. For anybody who writes and revises documents, there are two incredibly useful Microsoft Word commands that many (if not most) people don’t know. The hotkeys for these commands are: Alt + Shift + Down arrow Alt + Shift + Up arrow The first hotkey selects the entire paragraph and moves it DOWN by one paragraph. The second hotkey does the same but in the opposite direction. A cool thing about these two commands: they don’t involve the clipboard. The commands move entire paragraphs without the need to select, copy, cut, or paste. I emphasize: These commands act on the entire paragraph that contains the insertion point (cursor), whether or not text is selected. The same two hotkeys also work in PowerPoint text boxes, and in Outlook email messages (HTML and Rich Text only, not Plain Text). The challenge is to create Macro Express scripts to add these two hotkeys to other programs. You can choose any program you like, but here are a few examples you might want to consider: 1. WordPad: Move a paragraph up and down. 2. Notepad: Move a line up and down . (I don’t think it’s possible with paragraphs, but prove me wrong if you can!) 3. Excel: Move the entire row up and down. 4. Excel: Move the entire column left and right. (Perhaps use Alt + Shift + Left and Alt + Shift + Right) One hint: Although the built-in commands for moving paragraphs don’t use the clipboard, your Macro Express commands probably will!
  24. I wholeheartedly agree. At this point, continuing to improve this macro is, for me, an intellectual exercise -- a pastime, a way to while away some of the hours the pandemic has opened up. When you first posed this challenge, I thought it was fairly simple, as I came up with a working prototype without too much effort. But over time, your challenge has proven to be an unexpected goldmine of ideas about programming. In other words, it's the best kind of challenge.
  25. A thought on optimizing this macro. Sample random characters from the initial string. I have no idea how many, but my initial inclination would be to pick a small percentage, perhaps 1%. Then figure out the proportion of spaces in the sample. If the proportion of spaces is high, then iteratively delete some of the extra spaces before iteratively replacing space-space with space. If the proportion of spaces is low, immediately replace space-space with space.
×
×
  • Create New...