Capturing keys in editorgadget

Just starting out? Need help? Post your questions and find answers here.
BjornF
User
User
Posts: 35
Joined: Mon Jun 23, 2008 11:09 am
Location: Copenhagen

Capturing keys in editorgadget

Post by BjornF »

Is there an easy way to capture the keys as they are entered in the Editorgadget? (When the Return key is pressed I want the contents of the editorgadget to be transferred to a database, and the editorgadget "emptied".)

As far as I understand it "KeyboardPushed" etc don't activate the Waitevent, is that right? (The examples I have found all seem to be using Repeat - Until)

There is no menu-item for the event so I can't use the "AddKeyboardShortcut"

All the best / Björn
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Re: Capturing keys in editorgadget

Post by Arctic Fox »

For Windows you can use GetAsyncKeyState_(#VK_RETURN) or subclass the editor gadget.

Why can't you use AddKeyboardShortcut()? It seems to work fine.

Code: Select all

OpenWindow(0, 100, 100, 300, 300, "")
EditorGadget(0, 5, 5, 290, 290)

AddKeyboardShortcut(0, #PB_Shortcut_Return, 1)

Repeat
  Event = WaitWindowEvent()
  
  If EventMenu() = 1 And GetActiveGadget() = 0
    Debug GetGadgetText(0)
    SetGadgetText(0, "")
  EndIf
  
Until Event = #PB_Event_CloseWindow

End
BjornF
User
User
Posts: 35
Joined: Mon Jun 23, 2008 11:09 am
Location: Copenhagen

Re: Capturing keys in editorgadget

Post by BjornF »

I must have misunderstood the help file - I thought that you had to have a Menu item that was to be activated by the AddKeyboardShortcut().

Thank you for the rapid help :D

Björn
Post Reply