ListIcongadgt - catch keystrokes {FIXED}

Just starting out? Need help? Post your questions and find answers here.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

ListIcongadgt - catch keystrokes {FIXED}

Post 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
Last edited by kinglestat on Tue Dec 04, 2007 11:55 pm, edited 1 time in total.
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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
I may look like a mule, but I'm not a complete ass.
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Post 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?
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
User avatar
Blue
Addict
Addict
Posts: 964
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Post 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...
Last edited by Blue on Mon Apr 27, 2009 11:48 pm, edited 1 time in total.
PB Forums : Proof positive that 2 heads (or more...) are better than one :idea:
rdority
User
User
Posts: 34
Joined: Mon Mar 30, 2009 10:46 pm
Location: Vancouver, BC

yes thanks srod for this snippet!

Post 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! ;)
Post Reply