I'm not a programmer, I'm just learning. I'm trying to learn javascript using GJS and GNOME-Shell-extensions as examples. I'm trying to build an extension it has a ModalDialog with a Close button. from the button everything is closed without problems, but I want to add the ability to close it with the Escape key. in the code I have a signal handler like this
this.connect('key-press-event', () => {
but at least kill me, I do not understand how to handle this signal. I saw several similar questions here, and I tried the answer options in different ways, but I have either an error or an undefined one, help me, my head explodes. please explain to me how I need to work with 'key-press-event'.
I found a solution like this and it works. provided that there is a field for entering text and it is under focus. The trick here is that Clutter is the one to follow. And Clutter is a trash heap.
global.stage.set_key_focus(newEntry);
newEntry.connect('key-press-event', (o, e) => {
const symbol = e.get_key_symbol();
if (symbol === Clutter.KEY_Escape) {
log('what you need');
this._closeDialog();
}
else {
log('Not growth again' );
}
});
and here are three things that are incomprehensible to me. Why the first line (focus) does not work for me, for others it work, what are "o" and "e" and where did the get_key_symbol () method come from?
Try to go here. You can check for the keyboard event codes.