Delete MenuItem: shortcut (not working?)

Hi all,

to make a shortcut to the Edit.Clear MenuItem, we only have to put Del, DEL, Delete, DELETE in the shortcut field (design time).

My problem is that it does not work: only a beep is issued, the selected Row is not deleted. Of course, I have a MenuHandler that works fine when I choose Delete with the Mouse.

What didn’t I make?

[quote=132047:@Emile Schwarz]to make a shortcut to the Edit.Clear MenuItem, we only have to put Del, DEL, Delete, DELETE in the shortcut field (design time).

[/quote]

Where is this documented ?

Hi Michel,

In PDF, in this Forum, probably in docs. I search the sources:

a. PDF: Book 1: Fundamentals (176 pages) (UserGuide-Fundamentals.pdf,) page 71,
b. docs: MenuItem,
c. Forum: I let the reader make his own search.

But this not gives me an answer to my question.

Emile, I read the UserGuide - Fundamental page 71, and from what I can tell, it lists the keyboard shortcuts one can use in the IDE, not in code. And the “Del” mentioned in the left column refers to the Delete key, not any default value in any field.

The standard equivalent of the delete key in OS X is Fn-Backspace.

If you want to add your own custom shortcut, you must use a menu handler and place code into it to that effect.

Michel:

I cannot check right now, even if I cannot believe what you wrote (but you may be right !), so I will check this afternoon.

I’ll be back by tomorrow.

Did you check that in Xojo or is it from memory ?

I am not asking for your faith. I just carefully read the documentation. You can verify.

I happen to use that often… Never use belief. Always trust experimentation.

Be careful with that in the IDE…

OK, the PDF reference page is wrong. What about the reference in the documentation ?

fn-delete on OS X: does not works. I ALWAYS CHECK MORE THAN ONCE BEFORE ASKING QUESTION. BUT I CAN BE WRONG, this is why I check when requested. (sorry for the wrong caps).

Also, I forgot the screen shots:


BTW: when something does not works as I expect, I try to always check the documentation.

the relevant part in the docs is (docs: MenuItem):

[quote]
Specifying the keyboard shortcut in the Menu Editor

When you use the Properties pane in the Menu Editor, you specify the menu item’s shortcut key by assigning a key to the Key property and (normally) at least one modifier key. The Menu Editor translates your settings into the value for the KeyboardShortcut property.

You can use either a printable key or the following non-printable keys as shortcut keys: F1-F15, Tab, Enter, Space, Del (Delete), Return, Bksp (Backspace), Esc, Clear, PageUp, PageDown, Left, Right, Up, Down, Help, and Ins (Insert). If the shortcut key is more than one character and it is being set via code, the modifier key is not implied and must be explicitly defined. For example, the following line sets the Tab key as the shortcut key and uses the Ctrl key as the modifier. [/quote]

UserGuide-UserInterface.pdf, page 104 lacks the description of KeyboardShortCut.

Try enabling the menu item in the EnableMenuItems event

The delete (suppr in French) key in Windows deletes the character on the right, or what is selected. fn-Backspace does the same in Mac.

Now I experimented with a brand new desktop OSX project. In the edit menu, keditClear is already present under the option Delete, which standard shortcut is fn-Backspace, since there is no Delete key on the standard Mac keyboard.

But just to make sure, I plugged a PC keyboard in my iMac and the delete key works fine without any additional shortcut as well.

So forgive me, but I fail to understand what you want to do, since the Delete option is present in Edit as default, the fn-Backspace shortcut is already installed in the system, you do not need to add one. Indeed the menu will show a delete key, but it does not exist in OS-X, so it cannot be used. I even went as to put another key as shortcut (Z), and indeed, command-Z does trigger then the delete fine.

If you want the user to know which key to use for Delete, just enter fn-Delete as shortcut key for the EditClear menu item and make sure to set MenuModifier to off. It will show in the menu as shortcut.

What are you trying to achieve exactly ?

UserGuide-UserInterface.pdf, page 104 lacks the description of KeyboardShortCut.[quote=132075:@shao sean]Try enabling the menu item in the EnableMenuItems event[/quote]

Thank you. I will try.

What I wrote on the original post:

when one or many Rows is / are selected, if the user press the Delete Key from its keyboard, the selected Row(s) is (are) deleted.

I tried shao advice:

[code] If LB.ListIndex > -1 Then // LB is a ListBox
’ EditClear.Enable
End If

EditClear.Enable
[/code]

But none works.

Michel:
Activating the Edit.Clear (Delete in the Edit menu) MenuItem works like a charm.

BUT: with the properties as set in the two screen shots, nothing works with a Delete, alt-Delete, ctrl-Delete, cmd-Delete deptressed key(s). Only fn-Delete works (I certainly do not checked that because I do not asked for).

ON THE OTHER HAND: in Xojo IDE, the Delete key use works fine.

Thank you for the fn-Delete trick, I will use that… or not:

If you type in the Shortcut: Key field “fn-delete” you will get in the IDE-Menu Editor: fn-delete; and you Michel, did you get that too ?
At this stage, who will check what happens in the running or compiled application ?

BUT, in the running-in-the-IDE application, I get what you can see in the screen shot above.

EditClear.Enabled = (LB.ListIndex > -1)

No, sorry.

Fn-Delete is the way to get the Delete key (on laptops)… On the Mac keyboards the key labelled “Delete” is actually the backspace key, so you would need to either change your thinking and remember to use Fn-Delete or change the shortcut to Backspace where you can just press that key without the Fn modifier…

You are not doing anything wrong
Xojo is not doing anything wrong
The key is just labelled wrong

[quote=132210:@Emile Schwarz]Michel:
Activating the Edit.Clear (Delete in the Edit menu) MenuItem works like a charm.

BUT: with the properties as set in the two screen shots, nothing works with a Delete, alt-Delete, ctrl-Delete, cmd-Delete deptressed key(s). Only fn-Delete works (I certainly do not checked that because I do not asked for).

ON THE OTHER HAND: in Xojo IDE, the Delete key use works fine.

Thank you for the fn-Delete trick, I will use that… or not:

If you type in the Shortcut: Key field “fn-delete” you will get in the IDE-Menu Editor: fn-delete; and you Michel, did you get that too ?
At this stage, who will check what happens in the running or compiled application ?

BUT, in the running-in-the-IDE application, I get what you can see in the screen shot above.[/quote]

I did check the fn-Backspace works fine in a running application Delete Edit menu item.

Emile, you got to know that already modifier keys and backspace are taken by OS X. There is no Delete key on the Mac keyboard. The key on the top right corner is backspace, that is the reason why it shows an arrow to the left, back.

A lot of keys are already taken, as a matter of fact. You can see a list at http://support.apple.com/kb/HT1343

Backspace with modifier does all sorts of things. See https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts. What you cited where I believe you mean Backspace by delete :
alt-Delete, ctrl-Delete, cmd-Delete
alt-backspace : delete from the caret (curseur texte) up to the beginning of the word. If the caret is to the right of the word, delete the word
ctrl-backspace : nothing (backspace)
cmd-backspace : delete from the caret (curseur texte) up to the beginning of the line.

None of those keys is usable for a menu or redefined, as they are intercepted by Mac OS X before it reaches Xojo.
I tried to set ctrl-backspace as menu shortcut to clear, and although it seems to do nothing, it keeps doing backspace.

I experimented for you a number of modifier on X, but none works. Probably for the exact same reason as backspace combinations.

The best I could find is Ctrl-D, which may be easier to remember than fn-Backspace. Enter ‘D’ in the Key field, and set MacControlKey on.

Now, how does Xojo redefines the function keys ? I think they are probably using some measure of Keyboard.Keydown with a timer to monitor the keys. Which may very well explain the persistent inertia bug under Windows BTW. It works fine, I have used it now and then, but it is a lot less easy to use as a menu shortcut.

Coming to think of it, Ctrl-D is valid only in English. In French, the easier would be Ctrl-S for Supprime… In case you localize your app :wink:

Finally, it may be possible to use Backspace to erase your selected listbox columns : use the keydown and look for chr(8). Then do the appropriate deletion in code. It will require a bit more work, but it may be simpler for the user.

Michel: I will read your answer in a couple of minutes after I will finish to read the DNA Newspaper.

All:

All I want to do is to make the key know to clear something (a character, a selected set of characters, an item, whatever).

The name of the key is not relevant.

The Apple (very old) choose of backspace (or whatever the key is elsewhere) is not relevant.

All our users have to know is that pressing the key known as “Delete Key” is relevant.

Everything else is just matter of discussion.

BTW: in the IDE, the menu item called Delete appears like what you can see in my screen shot (the Edit Menu).

So, please keep focussed to the original question:

I want my users to delete one or many Rows from a ListBox (the selected Rows) using the delete key from their keyboard. The code works fine when the Delete MenuItem is selected with the Mouse.
Nothing is fired when the Delete key is depressed.

You can see whete the delete key is if you look at it in the following image:

I forgot to say that this must work on all Xojo platforms.

Take an eye on How to use the Delete key on a Mac.

OK. Fine. So the backspace key is marked delete. Whatever. Technically, a key that erases on the left is normally called Backspace. A key that erases on the right is called Delete. In all Apple documentation, the key they marked Delete is called backspace.

Please understand I am not trying to argue with you. I frankly do not care what keys are engraved with. I am simply trying to use the best and most precise communication. As a matter of fact, what is called Delete in the menu is yet another action. In Windows, and maybe some Mac programs (I do not feel like checking), it is called ‘Cut’ and in the menu item ‘clear’. It does not erase characters but when they are selected. But neither on the left or on the right. So for all intents and purposes, we have :

  • Backspace : erase to the left
  • Delete (fn-Backspace) : erase to the right
  • Delete menu item : erases selected text
  • Cmd-X : erases selected text and places it into the clipboard

Now, if all you need is a shortcut that does the same thing as Edit menu/Delete, use a key combination. I suggested Ctrl-D, but you can very well use Cmd-D inside your app, although it may be confusing for the user since Cmd-D is a finder shortcut : Selects the Desktop folder in Open and Save dialogs or selects Don’t Save in dialogs that contain a Don’t Save button.

Once again, I am not trying to convince you of anything, just trying to communicate with precision. Now Apple terminology seems somewhat inconsistent with ‘Delete’, so maybe we should say ‘Delete-PC’ for the fn-Delete on the Mac.

Now, I hope you know better what your options are : pick whatever key you want except Delete, and you should be fine.