# Call press button

**URL:** <https://forum.xojo.com/t/call-press-button/82949>\
**Category:** General\
**Created:** [October 23, 2024, 2:02pm UTC](https://forum.xojo.com/t/call-press-button/82949 "2024-10-23T14:02:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Federico\_Giannetti](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@Federico\_Giannetti](https://forum.xojo.com/u/Federico_Giannetti)\
**Post date:** [October 23, 2024, 2:02pm UTC](https://forum.xojo.com/t/call-press-button/82949/1 "2024-10-23T14:02:34Z")

</div>

Good afternoon group… how can I recall the click of a button without physically pressing it?  
Something like that

Call MyButton.pressed ?

I test my button name…PulsanteOKAggiorna.press but not work.

---

<div class="post-metadata">

**Author:** ![Louis\_D](https://forum.xojo.com/letter_avatar_proxy/v4/letter/l/cab0a1/32.png) [@Louis\_D](https://forum.xojo.com/u/Louis_D)\
**Post date:** [October 23, 2024, 2:05pm UTC](https://forum.xojo.com/t/call-press-button/82949/2 "2024-10-23T14:05:55Z")

</div>

You may simply move the code from the pressed event into a method and call that method from the pressed event instead. This way, you can also call the method from elsewhere.

edit: fixed typo.

---

<div class="post-metadata">

**Author:** ![Federico\_Giannetti](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@Federico\_Giannetti](https://forum.xojo.com/u/Federico_Giannetti)\
**Post date:** [October 23, 2024, 2:08pm UTC](https://forum.xojo.com/t/call-press-button/82949/3 "2024-10-23T14:08:33Z")

</div>

Yes, of course, I understood that. It’s just that I wanted to lighten the code, avoiding repeating the instructions having already written them somewhere else, in this case in the PRESSED event of the ButtonOkUpdate button

---

<div class="post-metadata">

**Author:** ![Louis\_D](https://forum.xojo.com/letter_avatar_proxy/v4/letter/l/cab0a1/32.png) [@Louis\_D](https://forum.xojo.com/u/Louis_D)\
**Post date:** [October 23, 2024, 2:15pm UTC](https://forum.xojo.com/t/call-press-button/82949/4 "2024-10-23T14:15:50Z")

</div>

The idea is not to copy the code, but to move it. It is only in one place. It is also a good idea to separate the logic from the UI. This way, the code is easier to adapt to a change in UI.

---

<div class="post-metadata">

**Author:** ![Federico\_Giannetti](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@Federico\_Giannetti](https://forum.xojo.com/u/Federico_Giannetti)\
**Post date:** [October 23, 2024, 2:17pm UTC](https://forum.xojo.com/t/call-press-button/82949/5 "2024-10-23T14:17:25Z")

</div>

By putting it in a Method?

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [October 23, 2024, 2:21pm UTC](https://forum.xojo.com/t/call-press-button/82949/6 "2024-10-23T14:21:21Z")

</div>

[https://documentation.xojo.com/api/user\_interface/desktop/desktopbutton.html#desktopbutton-press](https://documentation.xojo.com/api/user_interface/desktop/desktopbutton.html#desktopbutton-press)

And Louis is right: add a Method, Move (Copy/Paste) the code from the button to the Method and call that method from where you need (the Button, elsewhere).

---

<div class="post-metadata">

**Author:** ![Louis\_D](https://forum.xojo.com/letter_avatar_proxy/v4/letter/l/cab0a1/32.png) [@Louis\_D](https://forum.xojo.com/u/Louis_D)\
**Post date:** [October 23, 2024, 2:21pm UTC](https://forum.xojo.com/t/call-press-button/82949/7 "2024-10-23T14:21:43Z")

</div>

yes. the logic is no longer directly tied to the UI. Think for example abot creating a web version of a desktop app. you mostly change the ui, without the need to revisit the logic. It is obviously not so simple, but the example remains valid.

---

<div class="post-metadata">

**Author:** ![brian\_franco](https://forum.xojo.com/user_avatar/forum.xojo.com/brian_franco/32/156_2.png) [@brian\_franco](https://forum.xojo.com/u/brian_franco)\
**Post date:** [October 23, 2024, 2:22pm UTC](https://forum.xojo.com/t/call-press-button/82949/8 "2024-10-23T14:22:53Z")

</div>

Call PushButton.Press

```Press

Causes the button to be visually pressed, as well as triggering the Pressed event.

Call Press when the user has pressed the keyboard equivalent for the button to give the appropriate visual feedback.

This example presses Button1. It is called from another control.

Button1.Press
```

---

<div class="post-metadata">

**Author:** ![Federico\_Giannetti](https://forum.xojo.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@Federico\_Giannetti](https://forum.xojo.com/u/Federico_Giannetti)\
**Post date:** [October 23, 2024, 2:31pm UTC](https://forum.xojo.com/t/call-press-button/82949/9 "2024-10-23T14:31:20Z")

</div>

Ok Louis, I solved 🙂

Thanks.
