Page 1 of 1

ListIcongadgt - catch keystrokes {FIXED}

Posted: Tue Dec 04, 2007 10:09 pm
by kinglestat
I want to "catch" the delete key so a user can delete items from a listicongadget....how do I get that key? it doesnt seem to return any PB_....CHAR

Posted: Tue Dec 04, 2007 10:15 pm
by srod
Either add a keyboard shortcut or subclass the listicon and catch the #WM_KEYDOWN event or catch it in the PB event loop :

Code: Select all

If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateGadgetList(WindowID(0))
    ListIconGadget(0, 5, 5, 290, 90, "Name", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
    AddGadgetColumn(0, 1, "Address", 250)
    AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
    AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
    Repeat
      Event = WaitWindowEvent()
      If event = #WM_KEYDOWN And EventwParam() = #VK_DELETE And GetActiveGadget() = 0
        Debug "Delete key!"
      EndIf        
    Until Event = #PB_Event_CloseWindow
  EndIf
EndIf

Posted: Tue Dec 04, 2007 11:00 pm
by kinglestat
hadnt occured to me...thank....I'll try it

EDIT:
Worked straight through...thanks srod once again. How many kegs I owe you now? 17...18?

Posted: Thu Apr 24, 2008 1:58 pm
by Blue
Well what do you know?

A perfect solution to my problem too, closely related to the one posted by kinglestat

Thanks SRod.

I was using PureBasic's Keyboard Shortcut mechanism (Menu Event, etc) to intercept the Delete key on my program's dialog window. That worked well on the specific control that I had programmed it for, but it broke the regular behaviour of the Delete key on every other control of that form.

SRod's solution clears that problem completely. I get to apply my Delete function to the control i'm watching, AND Windows takes care of the Delete action on every other control.

I'd really like to understand why I can't get the PB mechanism to work in the same way.

Besides, SRod, where do you fish out the information on things like EventwParam() ? That's another mystery I'd like to solve...

yes thanks srod for this snippet!

Posted: Tue Apr 21, 2009 10:25 pm
by rdority
Thanks for this srod:

Code: Select all

      If event = #WM_KEYDOWN And EventwParam() = #VK_DELETE And GetActiveGadget() = 0
        Debug "Delete key!" 
I changed it to read as:

Code: Select all

      If event = #WM_KEYDOWN And EventwParam() = #VK_DELETE 

    activeGadget = GetActiveGadget()
    
    If activeGadget = #Email
      ;...delete from from list of emails
    ElseIf
      activeGadget = #AddressBook
      ;... delete row from Address book

    EndIf
Anyway, it's really great as you know because now, all of my regular text boxes are working again!

Before I had the side effect that the DEL key no longer worked in these regular text gadgets so the user would have had to use the Backspace.

That would be embarrassing.

Anyone notice that CraigsPal (works with Craigslist) has this problem!? I wonder if they used a Keyboard shortcut in PureBasic. Sure seems like it. Someone should tell them! ;)