Make "activate specific window" key cycle through windows


I created window rule, in which I assigned key shortcut for activating emacs window. The key always activates only first opened emacs window. Is it possible to modify it so it activates last used window or at least can cycle through all emacs windows when pressed multiple times?

My aim is to have a shortcut that (when pressed once or repeatedly) can:

  1. Run given app (emacs in this case)
  2. Activate it, if it’s already running (best - last used window, if it has multiple ones)
  3. Activate its next window, when pressed repeatedly.

I also tried using shortcuts (Meta+1/2/3/4/etc) for running taskbar pinned apps, and it works perfectly for other apps, but for me taskbar has problems with emacs.

Thank you for any suggestions.