Phew, what a long conversation for just a Return Key...
) and played with the Return Key my way...
because I think Windows' Return Key is to simulate a click on the default button...
Code: Select all
Procedure zOclick(Gadget.i) ;simulates a click on a gadget
GetCursorPos_(cp.POINT)
GetWindowRect_(GadgetID(Gadget),r.RECT)
SetCursorPos_((r\left+5),(r\top+5))
mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
SetCursorPos_(cp\x,cp\y)
EndProcedure
#WindowWidth = 390
#WindowHeight = 350
If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "PureBasic - Gadget Demonstration",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
Top = 10
GadgetHeight = 24
Frame3DGadget(#PB_Any, 10, Top, 370, 290, "Player...") : Top+20
StringGadget(0, 20, Top, 200, GadgetHeight, "")
PlayTop = Top : ButtonGadget(1, 223, PlayTop, 72, GadgetHeight, "Play",#PB_Button_Default)
StopTop = Top : ButtonGadget(2, 295, StopTop, 72, GadgetHeight, "Stop") : Top+35
TogglePlayStop=0; 0=Play, 1=Stop
DisableGadget(2,1)
GadgetToolTip(1,"Play the current song")
PanelGadget(3, 20, Top, #WindowWidth-50, #WindowHeight-Top-60)
AddGadgetItem(3, 0, "MP3 PlayList")
ListViewGadget(4, 6, 10, 230, 148)
For k=0 To 30
AddGadgetItem(4, -1, "Music Song n° "+Str(k))
Next
ButtonGadget(5, 250, 10, 80, GadgetHeight, "Add")
ButtonGadget(6, 250, 38, 80, GadgetHeight, "Remove")
ButtonGadget(7, 250, 66, 80, GadgetHeight, "Select")
GadgetToolTip(7, "Select the current song")
TrackBarGadget(17, 10, 168, 310, 25, 0, 100)
AddGadgetItem(3, 1, "Options")
Top = 10
CheckBoxGadget(10, 10, Top, 250, GadgetHeight, "Enable low-pass filter") : Top+30
CheckBoxGadget(11, 10, Top, 250, GadgetHeight, "Enable visual plug-in") : Top+30
ComboBoxGadget(12, 10, Top, 250, 21) : Top+30
AddGadgetItem(12, -1, "FireWorks")
AddGadgetItem(12, -1, "OpenGL spectrum")
AddGadgetItem(12, -1, "Bump bass")
SetGadgetState(12,0)
DisableGadget(12,1)
OptionGadget(13, 10, Top, 80, GadgetHeight, "640*480") : Top+20
OptionGadget(14, 10, Top, 80, GadgetHeight, "800*600") : Top+20
OptionGadget(15, 10, Top, 80, GadgetHeight, "1024*768")
SetGadgetState(13, 1)
ButtonGadget(16, 150, Top, 80, GadgetHeight, "Info")
CloseGadgetList()
TextGadget (9, 10, #WindowHeight-30, 250, 24, "PureBasic - Gadget demonstration")
ButtonGadget(8, #WindowWidth-100, #WindowHeight-36, 80, 24, "Quit")
SetGadgetState(3, 0)
AddKeyboardShortcut(0, #PB_Shortcut_Return, 15)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Menu
;
Select EventMenu()
Case 15
If TogglePlayStop=0
xx.s=GetGadgetText(0)
MessageRequester("Info", "Return key pressed, now Playing...", 0)
zOclick(1)
TogglePlayStop ! 1 ; this will toggle
Else
MessageRequester("Info", "Return key pressed, Music stopped!", 0)
zOclick(2)
TogglePlayStop ! 1
EndIf
; EndIf
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Case 1 ; Play
FreeGadget(1)
ButtonGadget(1, 223, PlayTop, 72, GadgetHeight, "Play")
FreeGadget(2)
ButtonGadget(2, 295, StopTop, 72, GadgetHeight, "Stop",#PB_Button_Default)
DisableGadget(2,0) ; Enable the 'Stop' gadget
DisableGadget(1,1) ; Disable the 'Play' Gadget
Case 2 ; Stop
FreeGadget(1)
ButtonGadget(1, 223, PlayTop, 72, GadgetHeight, "Play",#PB_Button_Default)
FreeGadget(2)
ButtonGadget(2, 295, StopTop, 72, GadgetHeight, "Stop")
DisableGadget(1,0) ; Enable the 'Play' gadget
DisableGadget(2,1) ; Disable the 'Stop' Gadget
Case 4
If EventType() = 2
SetGadgetText(0, GetGadgetText(4)) ; Get the current item from the ListView..
EndIf
Case 5 ; Add
AddGadgetItem(4, -1, "New Item Added...")
Case 6 ; Remove
RemoveGadgetItem(4, GetGadgetState(4)) ; Remove the current element of the ListView
Case 7 ; Select
SetGadgetText(0, GetGadgetText(4)) ; Get the current item from the ListView..
Case 8 ; Quit...
Quit = 1
Case 11 ; Enable PlugIn..
DisableGadget(12, 1-GetGadgetState(11))
Case 16 ;
If GetGadgetState(13) : Result$ = GetGadgetText(13) : EndIf
If GetGadgetState(14) : Result$ = GetGadgetText(14) : EndIf
If GetGadgetState(15) : Result$ = GetGadgetText(15) : EndIf
MessageRequester("Info", "Selected screen mode: "+Result$, 0)
Case 17
SetGadgetText(0, Str(GetGadgetState(17)))
EndSelect
EndSelect
Until Quit = 1
EndIf
End
So, even if you are on the TrackbarGadget, the Enter key will press either the Play or Stop button.
The interesting thing here is the addition of the zOclick procedure that emulates a click on a gadget, a procedure I found on the forum a long time ago, however I don't remember who wrote it...