---
title: "HardwareButton (_HardwareButton class)"
canonical: "https://docs.cuesystem.com/space/CVCHELP/512327711/HardwareButton%20(_HardwareButton%20class)"
format: markdown
---
> Macro (toc)

---

# IsPressed 

This function returns if a button is pressed. 

#### Syntax 

```visualbasic
Function IsPressed() As Boolean
```

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True if the button is pressed, False otherwise. 

# OnPush 

This event is raised when a button is pushed. 

#### Syntax* *

```visualbasic
Event OnPush()
```

#### Note 

Starting from firmware version 4.19 the programmer has to use the function EnableEvents if the link has to be active. 

# WaitWhilePressed 

This function waits while a button is pressed or until the timeout elapsed. 

#### Syntax 

```visualbasic
Function WaitWhilePressed(Optional timeout As Time := _TIME_INFINITE) As Boolean
```

#### Parameters* *

timeout 

<u>[Time](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Time)</u> Optional, defaults to _TIME_INFINITE. It is time to wait. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True if the button is pressed. It is False when the time elapsed. 

# EnableEvents 

This function enables the link to the hardware button. If the programmer links some process to the hardware button OnPush, then he/she has to use the command EnableEvents. For example inside the system Autoexec. 

#### Syntax 

```visualbasic
Public Function EnableEvents() As Boolean
```

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> True if the function succeeds. False otherwise. 

#### Example

```visualbasic
Process Autoexec() 
  Button1.EnableEvents() 
End Process 

Process Button1_OnPush Link Button1.OnPush() 
  Var releasetime As Time 

  If WaitUntilRelease(releasetime,:10.0) Then 
    // Button released in a time interval of less than 10 seconds 
  End If 
End Process
```

# DisableEvents 

This function disables the link to the hardware button. After using this function link to the hardware button is not active. For reactivating is necessary to use EnableEvents. 

#### Syntax 

```visualbasic
Public Function DisableEvents() As Boolean
```

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> True if the function succeeds. False otherwise. 

#### Example 

```visualbasic
Process Autoexec() 
  Button1.EnableEvents() 
End Process 

Process Button1_OnPush Link Button1.OnPush() 
  Var releasetime As Time 
  
  If WaitUntilRelease(releasetime,:10.0) Then 
    // Button released in a time interval of less than 10 seconds 
  Else 
    Button1.DisableEvents() 
    // link is not active, OnScreen menu shows after Button1 press. 
  End If 
End Process
```

# WaitUntilRelease 

This function is useful if it is necessary to know the press time of the hardware button. The programmer has to use this function inside the OnPush link process. 

#### Syntax 

```visualbasic
Public Function WaitUntilRelease (ByRef presstime As Time, Optional maxwaittime as time:=_time_infinite As Boolean
```

#### Parameters 

*Presstime* 

Return value takes the time between press and release of the button. If the function returns true, then the next calling of the function returns true too, but the presstime is set to zero. 

*Maxwaittime* 

Maximum time the function waits. If the timeout expires, the return value is false. 

#### Return value 

<u>[Boolean](/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> True if the function succeeds. False if the timeout expires. 

#### Example 

```visualbasic
Process Autoexec() 
  Button1.EnableEvents() 
End Process 

Process Button1_OnPush Link Button1.OnPush() 
  Var releasetime As Time 

  If WaitUntilRelease(releasetime,:10.0) Then 
    // Button released in a time interval of less than 10 seconds 
    // second call is nonsense but … 
    If WaitUntilRelease(releasetime,:10.0) Then 
      // function returns true immediately but … 
      DebugPrint(releasetime) // releasetime is set to zero 
    End If 
  Else 
    // here is it ok to call the function again,  
    // because the first call returns false - timeout 
    If WaitUntilRelease(releasetime,:10.0) Then 
      // releasetime is set to real value (total time between press and release) 
      DebugPrint(releasetime)   
    End If 
  End If 
End Process
```