0

Specify keystrokes for the space of an entire panel

asked 2012-04-19 09:06:23 +0800

gulsan gravatar image gulsan
9

updated 2012-04-19 10:00:26 +0800

Hi ZK Community =)

I am relatively new to ZK and busy trying to figure out how some things work, using the developer's reference. Right now I am looking into the handling of key events. I just experimented a bit and couldn't seem to specify keystrokes for the space of a panel/window. For example, I have a panel with multiple labels and textboxes. But the keystrokes I defined on the panel are only detected when one of the textboxes has the focus. So my question is how I can achieve that the whole panel listens to the specified keystrokes, regardless where I am within the panel. Hope you can give me some hints =)

Cheers,
Gulsan

Edit: I am using ZK 6.0.1

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2012-04-20 09:02:29 +0800

gulsan gravatar image gulsan
9
No one any ideas? With an example code, maybe you can help me.
<window title="Test Key Handling">

	<window  width="500" border="normal"> 
		<div id="testdiv" apply="test.Test" ctrlKeys="^s" forward="onOK">
			<panel>
				<panelchildren>
					<vlayout>
						<label value="textbox_1"></label>
						<textbox></textbox>
						<label value="textbox_2"></label>
						<textbox></textbox>
					</vlayout>
				</panelchildren>
			</panel>
		</div>
	</window>

</window>
public class Test extends GenericForwardComposer {
	
	public void onOK() {
		Messagebox.show("Enter pressed!", "Key Events", Messagebox.OK, null);
	}
	
	public void onCtrlKey(Event key) {
		Messagebox.show("CTRLKEY CTRL+S!", "Key Events", Messagebox.OK, null);
	}
	
}
What do I have to change/add so that the key events apply to an entire div, window, panel etc. ? Cheers Gulsan
link publish delete flag offensive edit

answered 2012-04-20 09:28:33 +0800

Matze2 gravatar image Matze2
773 7

Some hints: With "generic forwarding" your event handlers method names should be:
- onOK$testdiv
- onCtrlKey$testdiv
Remove the forward attribute at the div.

link publish delete flag offensive edit

answered 2012-04-20 11:01:51 +0800

gulsan gravatar image gulsan
9

Hi Matze, I did as you said but still the same as before. The events are only triggered when I set the cursor into one of the textboxes. The div or any other container doesn't listen to the events. I guess something else is needed here, just have to figure what that is ^^

link publish delete flag offensive edit

answered 2012-04-26 08:33:09 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi,

It is because a div can not receive the focus, and a component without focus can not receive the key event,
you may try to customize it, please refer to the sample:

ZKFiddle-Link

index.zul
<zk xmlns:w="client">
<div>Click in textbox_0 then press ctrl+s, you should see the 'message:' changed to 'message: textbox onCtrlKey at [current time]'</div>
<div>Click in the purple area then press ctrl+s, you should see the 'message:' changed to 'message: div onCtrlKey at [current time]'</div>
<window title="Test Key Handling">
<window width="500" border="normal">
<label id="msg" value="message: " />
<div id="testdiv" ctrlKeys="^s" style="background-color: #9999EE;">
<attribute w:name="bind_">
function (desktop, skipper, after) {
this.$bind_(desktop, skipper, after);

// create an anchor that can receive the focus
var anchor = zk.ie || zk.gecko ? document.createElement("a") : document.createElement("button");

// make it focusable
anchor.href = 'javascript:;';
// make it catchable
anchor.id = this.uuid + '-a';

// make it out of the screen
anchor.style.position = 'absolute';
anchor.style.left = '-3000px';
anchor.style.top = '-3000px';

// make it as a part of the div component
this.$n().appendChild(anchor);

// anchor listen to event focus, blur and keydown
this.domListen_(anchor, 'onFocus', 'doFocus_')
.domListen_(anchor, 'onKeyDown', 'doKeyDown_')
.domListen_(anchor, 'onBlur', 'doBlur_');
}
</attribute>
<attribute w:name="doClick_">
function (evt) {
// focus the anchor if click on self
if (evt.domTarget == this.$n())
jq(this.$n('a')).focus();
this.$doClick_(evt);
}
</attribute>
<attribute w:name="doFocus_">
function (evt) {
this.$doFocus_(evt);
// mantain focus status
if (evt.domTarget == this.$n('a'))
this._focused = true;
}
</attribute>
<attribute w:name="doBlur_">
function (evt) {
this.$doBlur_(evt);
// mantain focus status
if (evt.domTarget == this.$n('a'))
this._focused = false;
}
</attribute>
<attribute w:name="isListen">
function (evt, opts) {
// do not receive onCtrlKey event if self not focused
// see Widget.js#afterKeyDown_
if (evt == 'onCtrlKey')
return this._focused
return this.$isListen(evt, opts);
}
</attribute>
<attribute name="onCtrlKey">
msg.setValue("message: div onCtrlKey at " + new Date());
</attribute>

<label value="textbox_0"></label>
<div></div>
<textbox ctrlKeys="^s">
<attribute name="onCtrlKey">
msg.setValue("message: textbox onCtrlKey at " + new Date());
</attribute>
</textbox>
<panel>
<panelchildren>
<vlayout>
<label value="textbox_1"></label>
<textbox></textbox>
<label value="textbox_2"></label>
<textbox></textbox>
</vlayout>
</panelchildren>
</panel>
</div>
</window>
</window>
</zk>

Regards,
Ben

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-04-19 09:06:23 +0800

Seen: 192 times

Last updated: Apr 26 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More