Ignoring modifier key when typing a keystroke?

Hi,

Trying to improve my macros for working around the hijacking of word navigation/selection macros in Apple's Numbers.

The problem is that Numbers hijacks the standard opt-Left, opt-Right, opt-shift-Left and opt-shift-Right shortcuts (for word-by-word navigation and selection) when the cursor is not currently INSIDE a cell, for inserting columns to the left or to the right. I don't want that. It's too easy to insert columns accidentally when you're actually trying to navigate/select text inside a cell.

So I have a macro like this:

It uses the state of the “Duplicate Selection” menu item (disabled or enabled) to determine if the cursor is currently inside the cell or not. If it IS inside the cell (i.e. if the “Duplicate Selection” menu item is disabled), then the word-by-word navigation or selection works as expected. If the menu item is ENABLED, which means that the cursor is not currently inside the cell, it attempts to ENTER the cell by typing the option-Return keystroke.

The problem is that Shift is part of the trigger. And I keep Shift held down if I want to extend the selection by several words. (In other words, I don't release Shift between successive triggers.)

This means that when executing the last step in the macro (option-Return), KM still detects the Shift key as being down and triggers shift-option-Return instead of option-Return.

Is there a way to force KM to trigger option-Return without shift while Shift is still being held down?

I looked through the documentation and discussions, but cannot find an answer.

Thanks in advance.

Pierre

Hi Pierre,

That's a very interesting macro you have there and a very creative way of solving your problem. It's the second time in a few days I've seen using the 'if menu is selected/not selected' idea and it could be very useful.

I'm afraid I can't answer your question, but I could suggest a work around that I haven't tested. Would it be possible to use the system preference / keyboard / shortcuts / app shortcuts menu to change the default Numbers shortcuts to something else, say ctrl-opt-left and shift-ctrl-opt-left, or even something more obscure if you don't use them, leaving your 'extend selection to the left' etc macros to work without interruption? I don't know if it will work, if you uploaded your own macro I would give it a try myself, but it's a suggestion none-the-less, I've been thinking about similar things recently.
Best,
Damian

One can indeed use System Prefs › Keyboard › Shortcuts to assign another shortcut to Add Column Before, Add Column After, etc., but this does not remove the default option-Left, option-Right, which are probably assigned to these commands by Apple in a non-standard way.

As a reminder, option-Left, option-Right, etc. do work as expected once you've entered the cell, even though the Add Column Before, Add Column After, etc. menu commands remain enabled. So the shortcuts have effectively a dual meaning, depending the context: they behave as expected (for text navigation/selection) when you are in the process of editing the contents of a cell. They are only hijacked by Numbers for the other purpose when the cursor is not inside a cell. And that's what my macros are used to work around. (They only neutralize the shortcuts when the cursor is not already inside a cell.)

My macros successfully disable the hijacking, but I still have to manually enter the cell before I can use the shortcuts for text navigation/selection. I am trying to improve the macro by adding an action to enter the cell (with option-Return) when the cursor is not already inside the cell. That's the step that's not working properly because the Shift key in the shortcut interferes.

If there was a menu command for what option-Return, like “Edit Cell” or something, I could use that, but I can only find a menu command for "Edit Cell as Formula”, which is different.

Ahh. I see. You've thought about this in great detail, sorry my workaround doesn't help in this case. I hope someone else can help!

I should actually correct myself. When I said:

they behave as expected (for text navigation/selection) when you are in the process of editing the contents of a cell

I was mistaken or not accurate enough. The option-Left, option-Right, etc. shortcuts do work as expected once you've entered the cell, but only if you've entered the cell by double-clicking on it or pressing option-Return. If a cell is selected in Numbers, but you haven't entered it, when you type something (text or number), Numbers automatically enters the cell and inserts what you are typing, which is as expected, of course.

What is not expected is that, in that scenario, when you try to use option-Left, option-Right, etc., they still trigger the insertion of rows or columns even though you are inside the cell and the cursor is currently blinking and you might want to use them to navigate/select text (and also, sadly, even though the “Duplicate Selection” command is disabled!).

That's the crux of the problem I am trying to solve. The option-Left, option-Right, etc. shortcuts are hijacked even when you are inside the cell, with the cursor blinking, if you entered the cell by typing text or numbers instead of manually entering the cell by double-clicking on it or pressing option-Return.

I want to use my KM macros to prevent the hijacking. They only sort of work at present. I am trying to make them better, and my initial request is part of that.

In fact, my conclusion at this point is that what I am trying to do is impossible. I am trying to detect whether the cell was entered manually (by double-clicking on it or pressing option-Return) or automatically (by selecting it and then starting to type something over the selection). As far as I can tell, there is absolutely nothing in the Numbers UI that is different depending on the method of entry. So I cannot detect if the cell was entered manually or automatically, and therefore I cannot use KM to neutralize the hijacking of the option-Left, option-Right, etc. shortcuts when the cell is entered automatically.

So my initial request is not particularly relevant anymore. Even if I could get KM to ignore the Shift key while pressing option-Left or option-Right, that still wouldn't do anything for the main problem. Bummer.

Hi Pierre,

I've duplicated your macro, and played around with it in numbers. I think I finally understand what you're trying to do, but I'm not 100% certain, sorry for being dense.

  1. When you have entered a cell manually, is it the case that the macro works most of the time but occasionally fails? That's what I'm experiencing. It occurred to me that if the trigger didn't contain the shift key, then when the macro simulates opt-return, the shift wouldn't be an option. Still though, occasionally the macro failed when I changed the hotkey to ctrl-alt arrow, but either inserting a column (very rarely), or adding a carriage return to the cell (more common, but still somewhat rare).

Is there a reason why you need to have the shift key as part of the trigger? You can still be simulating shift-alt arrow with the macro. This is probably no help, but sometimes feedback can trigger other thoughts so I mention it in that spirit.

So you want to be able to go to a cell, start typing, and then use shift-alt-left arrow to select the word?

If you enter automatically, and then get the mouse to click in the cell, that would be like entering manually. This thread discusses how tricky that is: It is not possible to perform a left mouse click on the current keyboard text insertion position - #12 by tiffle

I did have a tiny amount of success with this: but it would need a lot more work and is inherently dodgy due to the text changing the screen, and the fact that the whole point is to select text to the left or the right. You may be right, it may be impossible, but there just may be a work around with mouse clicks, even if it takes you to the beginning of the cell each time? And then you use a different hotkey to highlight to the right perhaps? I don't know! Good luck!

Thanks for taking a closer look. It's a somewhat complex situation and there are several issues that need to be addressed.

When you have entered a cell manually, is it the case that the macro works most of the time but occasionally fails? That's what I'm experiencing.

There are two problems: one is in Numbers itself and one is in my macro. I started this thread with a discussion about the problem in my macro. Then I realized I had two problems, and the one in Numbers was way bigger than the one in my macro.

What you are addressing here is the one in my macro. The trigger necessarily includes the Shift key (since it's the shortcut I want to intercept), but the last step in the macro (Type the option-Return keystroke) doesn't work as expected if the Shift key isn't released in time, because then the Shift key modifies the keystroke and turns it into option-shift-Return, which doesn't do what I want. Hence my original question about whether there was a way to tell KM to ignore the Shift key (in case it hasn't been released yet) while executing the Type the option-Return keystroke action.

The bigger issue, however, is that Numbers's behaviour changes depending on how one enters the cell.

So you want to be able to go to a cell, start typing, and then use shift-alt-left arrow to select the word?

Exactly! I don't want to have to manually enter the cell first in order to avoid Numbers's hijacking of the shortcut for inserting a column to the left.

If you enter automatically, and then get the mouse to click in the cell, that would be like entering manually

It's an idea. The trick is to click in a way that does not alter the current position of the cursor and also does not slow things down significantly. It looks like clicking near the right edge of the cell might work… if there is no current selection (only the i-beam cursor). But if there is already an existing selection that I am trying to extend, it doesn't work, because it deselects the current selection. So the idea would be to only click once, before I have had a chance to create a selection. It might be feasible with a global variable, but I am not sure. I'll have to think about it.

Thanks for the suggestions!