Rookie Question

Just starting out? Need help? Post your questions and find answers here.
bhatkins2000
New User
New User
Posts: 9
Joined: Fri Apr 28, 2006 4:20 pm
Location: Missouri

Rookie Question

Post 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.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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
;==============================================================================
--Kale

Image
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post 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...
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post 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
I like logic, hence I dislike humans but love computers.
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Neat solution :D . Thanks.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Post Reply