Procedure.l MouseToGadget(GadgetID) hWnd.l If IsWindow_(GadgetID) hWnd=GadgetID ElseIf IsGadget(GadgetID) hWnd=GadgetID(GadgetID) Else ProcedureReturn #False EndIf GadgetRect.RECT GetWindowRect_(hWnd,@GadgetRect) ProcedureReturn SetCursorPos_((GadgetRect\left + GadgetRect\right) / 2,(GadgetRect\top + GadgetRect\bottom) / 2) EndProcedure If OpenWindow(0,0,0,500,250,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) ButtonGadget(1,10,10,100,20,"Test-Button",0) MouseToGadget(1) Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow EndIf