Thread: [Gambas-user] Highlight Editor - Capslock Key State
Brought to you by:
gambas
|
From: MaxVK <max...@gm...> - 2008-02-13 11:53:12
|
Hi there, I'm using the Highlight editor in Gambas2 and have added a status bar at the bottom of the editor window. I would like to be able to display the state of the capslock key there, but the problem I have is that while I can detect when capslock has been pressed, I cant seem to determine its state before the keypress. In other words I cant tell the state of the capslock key when the program is started, so I cant accurately display its state within the program because I have to make an assumption about its state in the first place. Can anyone point me in the right direction please? Thanks Max -- View this message in context: http://www.nabble.com/Highlight-Editor---Capslock-Key-State-tp15456466p15456466.html Sent from the gambas-user mailing list archive at Nabble.com. |
|
From: Stefano P. <ros...@ti...> - 2008-02-13 18:19:09
Attachments:
capslock-0.0.1.tar.gz
|
Alle 12:53, mercoledì 13 febbraio 2008, MaxVK ha scritto: > Hi there, I'm using the Highlight editor in Gambas2 and have added a status > bar at the bottom of the editor window. I would like to be able to display > the state of the capslock key there, but the problem I have is that while I > can detect when capslock has been pressed, I cant seem to determine its > state before the keypress. > > In other words I cant tell the state of the capslock key when the program > is started, so I cant accurately display its state within the program > because I have to make an assumption about its state in the first place. > > Can anyone point me in the right direction please? > > Thanks > > Max Hi, the attached example shows a raw dirty way to know if the capslock key is on/off on startup. Use at your own risk :-) Bye, Stefano |
|
From: MaxVK <max...@gm...> - 2008-02-13 20:21:14
|
Aha! Scrap the first message! It DOES work, but... The Form_KeyPress event would not seem to fire at all, so I added an invisible button to the form, and as the last line in the Form_Open event I added Button1.SetFocus. With the code from the Form_Activate event in your example in the Button1_GotFocus event the Keypress was now firing and the State of the capslock key was successfully read. Thanks again Stefano, I'm not sure why I had to change the code like that (Your example works on its own), but its working now. All the best Max Stefano Palmeri wrote: > > Alle 12:53, mercoledì 13 febbraio 2008, MaxVK ha scritto: >> Hi there, I'm using the Highlight editor in Gambas2 and have added a >> status >> bar at the bottom of the editor window. I would like to be able to >> display >> the state of the capslock key there, but the problem I have is that while >> I >> can detect when capslock has been pressed, I cant seem to determine its >> state before the keypress. >> >> In other words I cant tell the state of the capslock key when the program >> is started, so I cant accurately display its state within the program >> because I have to make an assumption about its state in the first place. >> >> Can anyone point me in the right direction please? >> >> Thanks >> >> Max > > Hi, > > the attached example shows a raw dirty way to know > if the capslock key is on/off on startup. > Use at your own risk :-) > > Bye, > > Stefano > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Gambas-user mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gambas-user > > -- View this message in context: http://www.nabble.com/Highlight-Editor---Capslock-Key-State-tp15456466p15466932.html Sent from the gambas-user mailing list archive at Nabble.com. |
|
From: Max <max...@gm...> - 2008-02-13 19:12:42
|
Hi Stefano, thanks for the example. It works fine of itself, but unfortunately when the code is transferred to my own project it doesn't seem to work. The code runs, but the state of the capslock key is not picked up. Nice try though and thanks! ;) All the best Max On Feb 13, 2008 6:19 PM, Stefano Palmeri <ros...@ti...> wrote: > Alle 12:53, mercoledì 13 febbraio 2008, MaxVK ha scritto: > > Hi there, I'm using the Highlight editor in Gambas2 and have added a > status > > bar at the bottom of the editor window. I would like to be able to > display > > the state of the capslock key there, but the problem I have is that > while I > > can detect when capslock has been pressed, I cant seem to determine its > > state before the keypress. > > > > In other words I cant tell the state of the capslock key when the > program > > is started, so I cant accurately display its state within the program > > because I have to make an assumption about its state in the first place. > > > > Can anyone point me in the right direction please? > > > > Thanks > > > > Max > > Hi, > > the attached example shows a raw dirty way to know > if the capslock key is on/off on startup. > Use at your own risk :-) > > Bye, > > Stefano > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Gambas-user mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gambas-user > > |
|
From: Benoit M. <ga...@us...> - 2008-02-13 20:08:09
|
On mercredi 13 février 2008, Max wrote: > Hi Stefano, thanks for the example. It works fine of itself, but > unfortunately when the code is transferred to my own project it doesn't > seem to work. The code runs, but the state of the capslock key is not > picked up. > > Nice try though and thanks! ;) > > All the best > > Max > Interesting problem. I don't know if there is a way to know the status of CAPS LOCK, or other modifier keys. -- Benoit Minisini |
|
From: Rob <sou...@ku...> - 2008-02-13 21:47:13
|
On Wednesday 13 February 2008 15:08, Benoit Minisini wrote:
> Interesting problem. I don't know if there is a way to know the
> status of CAPS LOCK, or other modifier keys.
I think there is. At the end of this post is the output of xev when I
press "a" three times, turning caps lock on and off in between.
Looking at the source of xev, the current status of the caps lock key
seems to be bit 1 (value of 2) in XKeyEvent->state, which seems to
correspond to the macro LockMask in X.h:
/* from xev.c */
const char *Yes = "YES";
const char *No = "NO";
/* ... */
static void do_KeyPress (XEvent *eventp)
{
XKeyEvent *e = (XKeyEvent *) eventp;
KeySym ks;
char *ksname;
/* ... */
printf (" state 0x%x, keycode %u (keysym 0x%lx, %s),
same_screen %s,\n",
e->state, e->keycode, (unsigned long) ks, ksname,
e->same_screen ? Yes : No);
}
/* the above outputs "state 0x2" when caps lock is on */
/* from X.h */
#define LockMask (1<<1) /* i.e., 0x2 */
So someone using gb.api could probably detect the caps lock key the
first time a key is pressed, after a little bit of painful libX11
manipulation. While this would only work when the user presses a
key, the state flag is also passed with XMotionEvent, and appears to
work the same way, so whenever the user moved the mouse you'd have
your caps lock state as well.
This doesn't seem to work for Scroll Lock, and I don't have a Num Lock
key on my laptop so I don't know whether that would work too.
Rob
KeyPress event, serial 31, synthetic NO, window 0x3c00001,
root 0x5d, subw 0x0, time 1286280441, (486,459), root:(489,543),
state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
XLookupString gives 1 bytes: (61) "a"
XmbLookupString gives 1 bytes: (61) "a"
XFilterEvent returns: False
KeyRelease event, serial 31, synthetic NO, window 0x3c00001,
root 0x5d, subw 0x0, time 1286280497, (486,459), root:(489,543),
state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
XLookupString gives 1 bytes: (61) "a"
XFilterEvent returns: False
KeyPress event, serial 31, synthetic NO, window 0x3c00001,
root 0x5d, subw 0x0, time 1286281927, (486,459), root:(489,543),
state 0x0, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyRelease event, serial 31, synthetic NO, window 0x3c00001,
root 0x5d, subw 0x0, time 1286282007, (486,459), root:(489,543),
state 0x2, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False
KeyPress event, serial 31, synthetic NO, window 0x3c00001,
root 0x5d, subw 0x0, time 1286282869, (486,459), root:(489,543),
state 0x2, keycode 38 (keysym 0x41, A), same_screen YES,
XLookupString gives 1 bytes: (41) "A"
XmbLookupString gives 1 bytes: (41) "A"
XFilterEvent returns: False
KeyRelease event, serial 31, synthetic NO, window 0x3c00001,
root 0x5d, subw 0x0, time 1286282933, (486,459), root:(489,543),
state 0x2, keycode 38 (keysym 0x41, A), same_screen YES,
XLookupString gives 1 bytes: (41) "A"
XFilterEvent returns: False
KeyPress event, serial 31, synthetic NO, window 0x3c00001,
root 0x5d, subw 0x0, time 1286283508, (486,459), root:(489,543),
state 0x2, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyRelease event, serial 31, synthetic NO, window 0x3c00001,
root 0x5d, subw 0x0, time 1286283587, (486,459), root:(489,543),
state 0x2, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False
KeyPress event, serial 31, synthetic NO, window 0x3c00001,
root 0x5d, subw 0x0, time 1286284033, (486,459), root:(489,543),
state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
XLookupString gives 1 bytes: (61) "a"
XmbLookupString gives 1 bytes: (61) "a"
XFilterEvent returns: False
KeyRelease event, serial 31, synthetic NO, window 0x3c00001,
root 0x5d, subw 0x0, time 1286284097, (486,459), root:(489,543),
state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
XLookupString gives 1 bytes: (61) "a"
XFilterEvent returns: False
|