ASP.NET Custom Server Controls: Extended Wordhack Control with Key Combination - Combining with the “Ctrl” key!
(Page 4 of 5 )
Until now, it has all worked very well. But what about supporting special keys in our web page? Perhaps we want “Ctrl+y” to go to www.yahoo.com, “Ctrl+g” to go to www.google.com, and so forth. Can we hack those as well? Why not?
Within my downloadable solution, I created a new control (apart from “WordHack”) called “CharacterHack”, as part of the same assembly. It is a totally different class with its own designer class. It is almost similar to the above “WorkHack” control, except with a few additions and modifications.
I changed the renamed “Word2Hack” property to “Character2Hack” property (accordingly in content as well). The other properties would be the same. The “Render” method would also be same. Notice also that “getJS4WordHack” and “getJS4WordParam” have been renamed to “getJS4CharacterHack” and “getJS4CharacterParam” (and accordingly in “AddAttributesToRender” method).
I added (or replaced) the following statements to the above JavaScripts at appropriate locations.
js &= "var SpecialCtrlStatus = new Array();"
js &= "var whichCtrlStatus = event.ctrlKey;"
js &= "eventChooser = event.keyCode+64;"
js &= "var which = String.fromCharCode(eventChooser).toLowerCase
();"
js &= "if (which == SpecialWord[i].charAt(SpecialLetter[i]) && "
js &= " (whichCtrlStatus == SpecialCtrlStatus[i])) "
“event.ctrlKey” is a JavaScript statement which retrieves the status of the “ctrl” key press. This is the heart of handling the “Ctrl” key. “event.keyCode+64” gives the proper ASCII value (for alphabets) when working with the “Ctrl” key. All the above modifications are to “getJS4CharacterHack”. And there really exists only one additional statement for “getJS4CharacterParam” as follows:
js &= "SpecialCtrlStatus[" & Val(Me.OrderOfPreference) & "]
=true;"
Apart from the above modifications (to support the “Ctrl” key), all of the rest would be the same as “WordHack” control.
Next: Summary >>
More ASP.NET Articles
More By Jagadish Chaterjee