1e41f4b71Sopenharmony_ci# Event Monopolization 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciYou can configure a component to monopolize events – built-in events and custom gesture events,<br> 4e41f4b71Sopenharmony_ciso that if the component first responds to an event in a window, it will be the only component that responds to the event. 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci> **NOTE** 7e41f4b71Sopenharmony_ci> 8e41f4b71Sopenharmony_ci> This feature is supported since API version 11. Updates will be marked with a superscript to indicate their earliest API version. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## monopolizeEvents 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_cimonopolizeEvents(monopolize: boolean) 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ciSets whether the component monopolizes events. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci**Parameters** 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci| Name | Type| Mandatory| Description | 24e41f4b71Sopenharmony_ci| ----------- | -------- | ------------------------ | ------------------------ | 25e41f4b71Sopenharmony_ci| monopolize | boolean | Yes| Whether the component monopolizes events.<br>Default value: **false**<br>**NOTE**<br>1. If a component is monopolizing events after a finger is pressed on it, and another finger is pressed before the first finger is lifted, the component continues to monopolize events while interacting with the second finger. The same case applies to a third and more fingers.<br>2. If a component is bound through [parallelGesture](ts-gesture-settings.md) to a gesture, for example, [pan gesture](ts-basic-gestures-pangesture.md), that can also be triggered by its child component, and the child component is configured to monopolize events, then the parent will not respond to the gesture after the child component has responded to it.| 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci## Example 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci```ts 30e41f4b71Sopenharmony_ci// xxx.ets 31e41f4b71Sopenharmony_ci@Entry 32e41f4b71Sopenharmony_ci@Component 33e41f4b71Sopenharmony_cistruct Index { 34e41f4b71Sopenharmony_ci @State message: string = 'set monopolizeEvents false' 35e41f4b71Sopenharmony_ci @State messageOut: string = ' ' 36e41f4b71Sopenharmony_ci @State messageInner: string = ' ' 37e41f4b71Sopenharmony_ci @State monopolize: boolean = false 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci build() { 40e41f4b71Sopenharmony_ci Column() { 41e41f4b71Sopenharmony_ci Text(this.message) 42e41f4b71Sopenharmony_ci .fontSize(22) 43e41f4b71Sopenharmony_ci .margin(10) 44e41f4b71Sopenharmony_ci Text(this.messageOut) 45e41f4b71Sopenharmony_ci .fontSize(22) 46e41f4b71Sopenharmony_ci .margin(10) 47e41f4b71Sopenharmony_ci Text(this.messageInner) 48e41f4b71Sopenharmony_ci .fontSize(22) 49e41f4b71Sopenharmony_ci .margin(10) 50e41f4b71Sopenharmony_ci Button('clean') 51e41f4b71Sopenharmony_ci .fontSize(22) 52e41f4b71Sopenharmony_ci .margin(10) 53e41f4b71Sopenharmony_ci // Change the value of the column's monopolizeEvents attribute through the button's click event. 54e41f4b71Sopenharmony_ci .onClick(()=>{ 55e41f4b71Sopenharmony_ci this.messageOut = " " 56e41f4b71Sopenharmony_ci this.messageInner = " " 57e41f4b71Sopenharmony_ci }) 58e41f4b71Sopenharmony_ci Button('change monopolizeEvents') 59e41f4b71Sopenharmony_ci .fontSize(22) 60e41f4b71Sopenharmony_ci .margin(10) 61e41f4b71Sopenharmony_ci // Change the value of the column's monopolizeEvents attribute through the button's click event. 62e41f4b71Sopenharmony_ci .onClick(()=>{ 63e41f4b71Sopenharmony_ci this.monopolize = !this.monopolize 64e41f4b71Sopenharmony_ci if (!this.monopolize) { 65e41f4b71Sopenharmony_ci this.message = "set monopolizeEvents false" 66e41f4b71Sopenharmony_ci } else { 67e41f4b71Sopenharmony_ci this.message = "set monopolizeEvents true" 68e41f4b71Sopenharmony_ci } 69e41f4b71Sopenharmony_ci }) 70e41f4b71Sopenharmony_ci Column() { 71e41f4b71Sopenharmony_ci Column(){} 72e41f4b71Sopenharmony_ci // When this.monopolize is true, clicking the inner column triggers only a touch event on it, but not on the outer column. 73e41f4b71Sopenharmony_ci // When this.monopolize is false, clicking the inner column triggers a touch event on it and the outer column. 74e41f4b71Sopenharmony_ci .monopolizeEvents(this.monopolize) 75e41f4b71Sopenharmony_ci .width('100%') 76e41f4b71Sopenharmony_ci .height('40%') 77e41f4b71Sopenharmony_ci .backgroundColor(Color.Blue) 78e41f4b71Sopenharmony_ci // Bind the inner column to the touch event. 79e41f4b71Sopenharmony_ci .onTouch((event:TouchEvent)=>{ 80e41f4b71Sopenharmony_ci if (event.type == TouchType.Down) { 81e41f4b71Sopenharmony_ci console.log("inner column touch down") 82e41f4b71Sopenharmony_ci this.messageInner = "inner column touch down" 83e41f4b71Sopenharmony_ci } 84e41f4b71Sopenharmony_ci }) 85e41f4b71Sopenharmony_ci } 86e41f4b71Sopenharmony_ci .backgroundColor(Color.Gray) 87e41f4b71Sopenharmony_ci .height('100%') 88e41f4b71Sopenharmony_ci .width('100%') 89e41f4b71Sopenharmony_ci // Bind the outer column to the touch event. 90e41f4b71Sopenharmony_ci .onTouch((event)=>{ 91e41f4b71Sopenharmony_ci if (event.type == TouchType.Down) { 92e41f4b71Sopenharmony_ci console.log("outside column touch down") 93e41f4b71Sopenharmony_ci this.messageOut = "inner column touch down" 94e41f4b71Sopenharmony_ci } 95e41f4b71Sopenharmony_ci }) 96e41f4b71Sopenharmony_ci } 97e41f4b71Sopenharmony_ci .height('100%') 98e41f4b71Sopenharmony_ci } 99e41f4b71Sopenharmony_ci} 100e41f4b71Sopenharmony_ci``` 101e41f4b71Sopenharmony_ci 102