chuck
New Member
Posts: 2
|
Post by chuck on Aug 5, 2020 19:26:23 GMT
I have accidentally discovered that a listbox responds to more than just mouse clicks and the up-down arrows. It also responds to [Home], [End], [Page Up] and [Page Down]. Furthermore, a letter key can jump the highlight around among items starting with that letter. A left or right arrow will move the highlight up or down one step, but then switches focus away from the listbox so that the up/down keys no longer work until I restore focus by clicking inside the listbox. These things may be known to experts, but I list them because I found the information nowhere else, and it might help other newbies. The question that brought me to this investigation: Is there any way to trap other keystrokes while a listbox has focus?
I would like to have [Enter] select the highlighted item, as if it were double-clicked, and have [spacebar] do something different. I can do it by directing focus to a window, and handling every mouse click and keystroke myself, but is there an easier way?
|
|
|
Post by Rod on Aug 6, 2020 8:11:25 GMT
I have amended the help file example. I added a .default button and dialog window type that reacts when enter is pressed and I set up the initial selection and focus on startup. Now you can key the initial letter to select an item or toggle through similar items. You can use the up/down arrow keys the Home End keys and the Enter key to make your choice. It is pretty slick if you know what keys to use. It also responds to the mouse.
However it won't respond to other keys like space, you would need to explain what you are trying to do. It is the very fact that you can key the initial letter that prohibits other hotkey combinations.
See if this helps.
'Sample program. Pick a contact status 'amended to include .default button and window type dialog 'also preselect item 1 and set focus on start
options$(0) = "Cold Contact Phone Call" options$(1) = "Send Literature" options$(2) = "Follow Up Call" options$(3) = "Send Promotional" options$(4) = "Final Call" listbox #status.list, options$(), [selectionMade], 5, 35, 250, 90 button #status.default, "Continue", [selectionMade], UL, 5, 5' # button #status.canc, "Cancel", [cancelStatusSelection], UL, 100, 5 WindowWidth = 270 : WindowHeight = 180 open "Select a contact status" for dialog as #status #status.list "selectindex 1"' # #status.list "setfocus" ' # wait
[selectionMade] print #status.list, "selection? selection$" notice selection$ + " was chosen" close #status end
[cancelStatusSelection] notice "Status selection cancelled" close #status end
'standard Windows ListBox shortcut keys 'Up/Down arrow keys – move to previous /next item. 'Page Up / Page Down – move to item on previous / next page (based on size of ListBox) 'Home / End – move to first / last item in last. 'Enter single character – move to next item that begins with that character.
|
|
|
Post by tsh73 on Aug 6, 2020 12:26:24 GMT
Wow. Cool.
Pressing intitial letter jumps to next word with same letter, no sor needed.
|
|
chuck
New Member
Posts: 2
|
Post by chuck on Aug 6, 2020 12:35:07 GMT
Perfect! Thanks, Rod.
It makes perfect sense that the first-letter function blocks other key handling.
I see in your example that the left-right arrows shift focus within the dialog box, but simultaneously bump the listbox highlight up or down. Is that a bug or a feature?
I can hide the default button and it still works. The other button can do what I had been doing with the spacebar. My external-to-the-listbox handling had not included keys beyond up, down, spacebar & enter.
To explain my program needs: My wife had a stroke that affected her right side and her ability to say (and to some extent hear) nouns, so I developed a set of programs to exercise different abilities: Click-It -- hand-eye coordination Hear-It -- match picture to spoken word Match-It -- pair text with picture Spot-It -- visually locate a symbol on the screen Type-It -- type the word shown Write-It -- write the word shown Each program advances in difficulty with success. The programs can be used by multiple people, and each user of each program has an individual file of progress and personal preferences. I will gladly share these programs with anyone who needs them. CGaston@aol.com
As a program starts, it presents a list of users. Thanks to you, I can now easily use all the functionality of a listbox, plus the ability to select with the enter key (double-click can be difficult for my wife). My [spacebar] function, now to be done with a button, calls up a screen that allows adding or deleting users, or modifying parameters such as colors or limits on difficulty.
|
|
|
Post by Rod on Aug 6, 2020 18:30:49 GMT
I have to admit I was not aware of the alpha key search but it works well. It’s a Windows thing, hotkeys are either your thing or not. I tend to use the mouse hence my ignorance.
I suspect the right and left keys are there for multi column listboxes which are not a feature of Just BASIC.
However I think you have a neat solution for a single listbox. Moving between controls, buttons boxes etc can be done with Tab key but whether that change of focus is obvious enough we need to see.
|
|