Hotkey binds a key or a key combination to a client side handler or to an Ajax request. In the first example the "left" and "right" keys switch the images, in the second one the combination ctrl+shift+s sends an Ajax request that calls an action of the bean. A hotkey is not triggered while an input has the focus.
<style>
/* the images (500 x 313) scale down with the card on small screens */
.hotkey-switch {
width: 500px !important;
max-width: 100%;
height: auto !important;
aspect-ratio: 500 / 313;
}
.hotkey-switch img {
max-width: 100%;
height: auto;
}
</style>
<div class="card">
<h:form>
<h5 class="mt-0">ImageSwitch Integration (Left-Right)</h5>
<p:imageSwitch effect="fade" ref="switcher" slideshowAuto="false" styleClass="hotkey-switch">
<p:graphicImage name="demo/images/nature/nature1.jpg"/>
<p:graphicImage name="demo/images/nature/nature2.jpg"/>
<p:graphicImage name="demo/images/nature/nature3.jpg"/>
<p:graphicImage name="demo/images/nature/nature4.jpg"/>
</p:imageSwitch>
<p:hotkey bind="left" handler="PF('switcher').previous()"/>
<p:hotkey bind="right" handler="PF('switcher').next()"/>
<h5>Ajax Hotkey (ctrl + shift + s)</h5>
<p:growl id="msgs" showDetail="true" skipDetailIfEqualsSummary="true"/>
<p:hotkey bind="ctrl+shift+s" update="msgs" action="#{hotkeyView.save}"/>
<div class="formgrid grid p-fluid">
<div class="field col-12 md:col-6">
<p:outputLabel for="text" value="Text"/>
<p:inputText id="text" value="#{hotkeyView.text}"/>
</div>
</div>
</h:form>
</div>