Page 1 of 1
Rookie Question
Posted: Wed Oct 11, 2006 9:14 pm
by bhatkins2000
I have an application that I am developing that needs to have a Return Key event in a string gadget trigger some actions. I cant seem to get it to work. Does anyone have some code that does this?
Thanks.
Posted: Wed Oct 11, 2006 11:03 pm
by Kale
Code: Select all
;==============================================================================
;-CONSTANTS
;[=============================================================================
#APP_NAME = "PRESS RETURN"
Enumeration
#WINDOW_ROOT
#STRING_MAIN
#RETURN_EVENT
EndEnumeration
;]=============================================================================
;-PROCEDURES
;[=============================================================================
;Handle an error
Procedure HandleError(Result.l, Text.s)
If Result = 0
MessageRequester("Error", Text, #PB_MessageRequester_Ok)
End
EndIf
EndProcedure
;]=============================================================================
;-GEOMETRY
;[=============================================================================
HandleError(OpenWindow(#WINDOW_ROOT, 0, 0, 400, 300, #APP_NAME, #PB_Window_SystemMenu | #PB_Window_ScreenCentered), "Main window could not be created.")
HandleError(CreateGadgetList(WindowID(#WINDOW_ROOT)), "Gadget list for the main window could not be created.")
StringGadget(#STRING_MAIN, 10, 10, 380, 22, "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.")
AddKeyboardShortcut(#WINDOW_ROOT, #PB_Shortcut_Return, #RETURN_EVENT)
;]=============================================================================
;-MAIN LOOP
;[=============================================================================
Repeat
EventID.l = WaitWindowEvent()
Select EventID
Case #PB_Event_Menu
Select EventMenu()
Case #RETURN_EVENT
Debug "He he, we fooled the window that we had a menu event triggered."
Debug ""
Debug "String gadget text: " + GetGadgetText(#STRING_MAIN)
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
End
;]=============================================================================
;-END
;==============================================================================
Posted: Thu Oct 12, 2006 11:32 am
by Inf0Byt3
Speaking of this, I've seen that AddKeyboardShortcut() works only once for a single window. Is this a bug or a feature, because i must handle a big number of open windows, but it seems that if i add a keyboard shortcut for each window, only the one from the main window works...
Posted: Thu Oct 12, 2006 11:57 am
by Joakim Christiansen
Here is something I did once...
Code: Select all
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case #Main_Message ;my string gadget
If GetAsyncKeyState_(#VK_RETURN) = -32767 ;if return is pressed
PostMessage_(WindowID(#Main),#WM_COMMAND,#PB_EventType_LeftClick,GadgetID(#Main_Send)) ;click my send button
EndIf
EndSelect
EndSelect
Posted: Thu Oct 12, 2006 12:26 pm
by Inf0Byt3
Neat solution

. Thanks.