XWidgetSoft Forum

XWidget & XLaunchpad , Desktop customization
It is currently 2017年 Oct 18日 01:15

All times are UTC - 8 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: 2015年 Dec 9日 06:25 
Offline
User avatar

Joined: 2013年 Jul 29日 09:13
Posts: 563
To capture the use of the ctrl key whilst using the scrollwheel I would use the following javascript code. See the event keywords in the code sample below:

Code:
backplate.onMouseWheel = function (event) {
   var size = Number(preferences.scalePref.value),
        maxLength = Number(preferences.scalePref.maxLength),
        minLength = Number(preferences.scalePref.minLength),
        step = 10;

    if (event.ctrlKey) {
       if (event.scrollDelta > 0) {
           size += step;
           if (size > maxLength) {
               size = maxLength;
           }
       } else if (event.scrollDelta < 0) {
           size -= step;
           if (size < minLength) {
               size = minLength;
           }
       }
       preferences.scalePref.value = String(size);
       resize();
   }
};

What is the equivalent method to obtain the CTRL keypress within Xwidget?


Last edited by yereverluvinuncleber on 2017年 Jun 28日 05:56, edited 3 times in total.

Top
 Profile  
 
PostPosted: 2015年 Dec 9日 06:33 
Online
User avatar

Joined: 2012年 Dec 5日 17:52
Posts: 4548
Check this widget and the script:
http://subhanulhaque.deviantart.com/art ... -339438490
This guy created a virtual keyboard..

_________________
Image
...and remember: don't take life too seriously...
My profile on Deviantart: http://jimking.deviantart.com/


Top
 Profile  
 
PostPosted: 2015年 Dec 9日 07:17 
Offline
User avatar

Joined: 2013年 Jul 29日 09:13
Posts: 563
Thanks Jim for the attempt to help.

Yes he did create a virtual keyboard but he didn't capture a CTRL key, his keyboard just has images that respond and add characters on a screen. There was no ctrl key and he didn't handle the event. Interesting widget though...


Top
 Profile  
 
PostPosted: 2015年 Dec 9日 07:42 
Online
User avatar

Joined: 2012年 Dec 5日 17:52
Posts: 4548
I found this:
http://help.adobe.com/en_US/AS2LCR/Flas ... 00520.html

_________________
Image
...and remember: don't take life too seriously...
My profile on Deviantart: http://jimking.deviantart.com/


Top
 Profile  
 
PostPosted: 2015年 Dec 9日 17:23 
Offline
User avatar

Joined: 2013年 Jul 29日 09:13
Posts: 563
Let me see what I can do with it.


Top
 Profile  
 
PostPosted: 2015年 Dec 23日 16:27 
Offline
User avatar

Joined: 2013年 Jul 29日 09:13
Posts: 563
It seems that you cannot capture keypress events when manipulating any object other than an text edit box or similar. This is a problem as it means that a press of the CTRL key when the mouse is over the widget cannot be captured even though we have an onKeyDown event set up and code assigned. The event is simply ignored.

I tested a very large edit box at an opacity of 1 that can be set over the whole widget, this would have allowed a CTRL key to be captured, unfortunately mouse-through does not seem to work with edit boxes so all other onMouse events for all other images sitting below are negated when a large edit box is positioned above them.

So, to sum up: Xwidgets has an incomplete implementation of onKeyDown event that does not currently function on image objects. This is a BUG. Changing the title of this thread to a BUG.


Top
 Profile  
 
PostPosted: 2017年 Apr 25日 05:23 
Offline
User avatar

Joined: 2013年 Jul 29日 09:13
Posts: 563
BUMP:

This bug is a very serious one, it means that Xwidgets cannot respond to keypress events. That makes it useless for creating keyboard driven apps that respond to key events.

For example, when using youtube to display videos the spacebar, cursor and other keys can be used to control the video. These keypresses have become the standard for media players and allow the user to interact with the app using the keyboard if he wishes.

Xwidget does not allow this interaction due to a shoddy implementation of the keydown event.


Top
 Profile  
 
PostPosted: 2017年 Jun 28日 06:13 
Offline
User avatar

Joined: 2013年 Jul 29日 09:13
Posts: 563
Workaround

I tried various methods of getting round this, I tested a very large edit box at an opacity of 1% that can be set over the whole widget, this would have allowed a CTRL key to be captured. Unfortunately, mouse-through does not seem to work with edit boxes so all onMouse events for all other objects sitting below are negated when a large edit box is positioned directly above them.

There is however a isKeyDown() function that checks for a keydown event that actually works...

To capture a keydown event the isKeyDown() function has to be inserted into a place in your code, typically an event function. For example, during a onMouseDown event this code might be inserted:

Code:
if (isKeyDown(40)) {
// right volume up
if (debugFlg === 1) {print("%KON-I-INFO, pressing down the cursor UP key ");};
sliderSet.left = sliderSet.left - 10 ;
limitSliderSet();
}

However, this would only capture the keydown event when the mousekey was pressed simultaneously. So, we have to be inventive to ensure that the only trigger for the keypress is the keypress itself and as a result it needs to be inserted into something keyboard/mouse-neutral that occurs all the time... there aren't many of those - except for a timer event!

Create a timer called keyTimer and set the frequency to 50ms, insert the above code into the keytimerOnUpdate function. This will cause the timer to activate the function every 50ms and determine whether a valid keypress has been made. This is the workaround I was looking for, a bit over-complex for a simple key capture but in the absence of a working onKeyDown function it must suffice.

The isKeyDown(keyCode) function uses the standard javascript keyboard scan codes to determine which key is pressed. Find those here: keycode.info/

There is an unexpected side-effect, the key capture occurs all the time and not just when the widget has focus. The isKeyDown function works whether you are typing into a word processor or writing an email, if the widget is running on your dektop you will find the media player reacting seemingly randomly to your email keypresses. To get round this you simply need to turn off the timer when your mouse leaves the widget and then turn the timer back on when the mouse re-enters. In the IDE in design mode, select the WIDGET object and enable an event for both entering and leaving the widget, assigning the following code:

Code:
function widgetOnEnter()
{
keyTimer.enabled=true;
}

function widgetOnLeave()
{
keyTimer.enabled=false;
}

The regular frequency of the timer could be increased to 100ms interval to reduce the cpu overhead of such a frequently run timer. Unfortunately, the result would be that keypresses would seem 'halting' and jerky in their capture. The 50ms interval makes for smooth response while a 100ms interval feels unresponsive and 'wrong'. There is a cpu penalty for frequently running such a function and it is only necessary due to incomplete features in the Xwidget engine.

However, we have a workaround for the absence of the onKeyDown event and it means that we can now say that Xwidget does have the ability to capture a keyboard event.

Note that this is a limited workaround as the mouse cursor needs to be hovering over the widget in order for this to work. It should operate when the widget gains focus and only stop capturing keypresses when the widget loses focus.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group