OK, I admit it must be my code - I'm probably overlooking or missing something, hence I'm not that great with eventbubbling.
 
Actually I wasn't totally satisfied with the code as it were when releasing the ccreation widgetset, because I want to lock it down to one modifier key so it can be truly cross-browser (menaing across OSes too). The one key to cover most are the ALT-key (at least that was my conclution from reading the following article http://www.webreference.com/js/column11/modifierkeys.html ).
 
Anyway, here's my code:
 
ccreation.ext.keyevents.js
=================== 
 
KeyEvent=function() {}
 
KeyEvent.prototype.getSource=function() {return this.src}
 
KeyEvent.prototype.setEvent=function(src,e) {
 
 this.src=src
        this.which=(is.ns4)?e.which:e.keyCode
 this.controller=false;
 var curKey = String.fromCharCode(this.which).toLowerCase()
 
 //we don't want enter to be recognized whenever we press OK, cause then we may never get out of the loop
 // if (this.which==13) { this.charKey = '[unknown]'; return false; } --> not working either
 
 if (((curKey>='a')&&(curKey<='z'))||((curKey>='0')&&(curKey<='9'))) this.charKey = curKey;
 
// I changed the NS4 code here, but it wasn't working before either
 
this.controller = (is.ns4)? e.modifiers & Event.ALT_MASK : e.altKey; 
this.orig=e
return this
}
 
KeyEvent.prototype.getKey=function() {return this.charKey}
KeyEvent.prototype.getControllerState=function() {return this.controller}
 
DynDocument.prototype.keys=new KeyEvent()
DynDocument.prototype.captureKeyEvents=function() {
 if (this.KeyEventsCaptured) return
 this.KeyEventsCaptured=true
 if (!this.eventListeners) this.eventListeners=[]
 this.hasEventListeners=true
 if (is.ns4) this.doc.captureEvents(Event.KEYPRESS | Event.KEYDOWN | Event.KEYUP | Event.ALT)
 this.doc. {
  if (is.ie) var e=this.lyrobj.elm.event
  var realsrc=is.ie?e.srcElement:e.target
  var src=realsrc.lyrobj
  if (!src) {
   src=DynAPI.getDocument(realsrc.elm)
   if (!src) return true
  }
  var evt=this.lyrobj.keys
  evt.setEvent(src,e)
         src.invokeEvent(e.type,evt)
 }
}
 
And the page it goes in (examples/ccreation.extkeyevents.htm):
*************************************************************************
 
<html>
<head>
<head><title>ComicCreation Keyevents Extension</title>
</head>
 
<script language="Javascript" src="../src/dynapi.js"></script>
 
<script language="Javascript">
 
DynAPI.setLibraryPath('../src/lib/')
 
DynAPI.include('dynapi.api.*')
DynAPI.include('ccreation.ext.keyevents.js')
 
DynAPI. {
 
 myLayer = new DynLayer()
 
 myLayer.setSize(200,200)
 myLayer.setBgColor('#c0c0c0')
 myLayer.moveTo(100,100)
 myLayer.setHTML("Hold 'ALT' \(control-key\) and press \'m\' to move me.")
 

 myListener = new EventListener(DynAPI.document)
 
  myListener. {
   if (e.altKey&e.charKey=='m') myLayer.moveBy(120,120)
  }
  myListener. {
 
  }
  myListener. {
 
  }
 

 DynAPI.document.addEventListener(myListener)
 
 DynAPI.document.addChild(myLayer)
 
}
 
</script>
 
<body>
 
and if you're debugging you must have included in dynapi.js as described below for it to work:
***********************************************************************************************************
 
 loadHandler : function() {
   [...]
      if (DynAPI.document.captureMouseEvents) DynAPI.document.captureMouseEvents()
  Add this ---> if (DynAPI.document.captureKeyEvents) DynAPI.document.captureKeyEvents()
      DynAPI.loaded=false;
   [...]
 
=================
 
Thanks for considering! :)
 
Henrik V�glin [ [EMAIL PROTECTED] ]

Reply via email to