Key Event

From Documentation




  • onCtrlKey
    This event is fired when a user presses a key specified in ctrlKeys attribute. If you do not set ctrlKeys, Spreadsheet handle keys with default value including ctrl+x, ctrl+c, ctrl+v, ctrl+d, ctrl+b, ctrl+i, ctrl+u, and delete key. For syntax to set ctrlKeys, please refer to ZK Developer's Reference/UI Patterns/Keystroke Handling. When the corresponding event listener is invoked, a KeyEvent object is passed as an argument.


Zss-essentials-events-key.png

In above screenshot, the messages show that ctrl+c is pressed firs then ctrl+v. Let's see how to make it:

public class EventsComposer extends SelectorComposer<Component>{
	//omitted codes...

	@Listen("onCtrlKey = spreadsheet")
	public void onCtrlKey(KeyEvent event){
		StringBuilder info = new StringBuilder();
		
		info.append("Keys : ").append(event.getKeyCode())
			.append(", Ctrl:").append(event.isCtrlKey())
			.append(", Alt:").append(event.isAltKey())
			.append(", Shift:").append(event.isShiftKey());
		
		//display info...
	}
}
  • Line 8~10: We can also know that control, alt, or shift key are pressed or not via KeyEvent.