I am looking at a user interface issue where it might be convenient to detect a press of the control key, by itself. Not ctrl-a. Just press and release of control. Can I detect this using Visual Works Smalltalk?
Regards,
Rick
-- I insist on rapport! _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
As far as I know, you can detect that it IS pressed, but not detect
that act of pressing or releasing.
You can test control keys and mouse buttons using WindowSensor new shiftDown / ctrlDown / altDown / redButtonPressed / yellowButtonPressed On Mar 12/11 5:43 PM, Rick Hedin wrote:
-- Dennis Smith +1 416.798.7948 Cherniak Software Development Corporation Fax: +1 416.798.0948 509-2001 Sheppard Avenue East [hidden email] Toronto, ON M2J 4Z8 <a class="moz-txt-link-freetext" href="sip:dennis@CherniakSoftware.com">sip:dennis@... Canada http://www.CherniakSoftware.com Entrance off Yorkland Blvd south of Sheppard Ave east of the DVP _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
In reply to this post by Rick Hedin
Hello,
we faced the same problem a few months ago. We ended up with a simple package that adds ModifiersChangeEvent which is a MouseEvent that informs about modifier key changes. Note however that the package contains two overrides (in EventSensor). All you have to do is to implement a method modifiersChangeEvent: aModifiersChangeEvent in your Controller or SelectionTracker subclasses. The package is from 7.7 image and dependes only on the VW base so should work as is. HTH, Ladislav Lenart Rick Hedin wrote: > I am looking at a user interface issue where it might be convenient to > detect a press of the control key, by itself. Not ctrl-a. Just press > and release of control. Can I detect this using Visual Works Smalltalk? > > > Regards, > > Rick > > -- > I insist on rapport! > > > ------------------------------------------------------------------------ > > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc <?xml version="1.0"?> <st-source> <time-stamp>From VisualWorks®, 7.7 of 15. prosince 2009 on 14. bÅezna 2011 at 09:30:05</time-stamp> <component-created> <name>ModifiersChangeEvent</name> <type>package</type> </component-created><!-- Package ModifiersChangeEvent(1.1,ladislav)= --> <component-property> <name>ModifiersChangeEvent</name> <type>package</type> <property>prerequisiteParcels</property> <value>#(#('Base VisualWorks' ''))</value> </component-property> <component-property> <name>ModifiersChangeEvent</name> <type>package</type> <property>developmentPrerequisites</property> <value>#(#(#any 'Base VisualWorks' ''))</value> </component-property> <component-property> <name>ModifiersChangeEvent</name> <type>package</type> <property>prerequisiteDescriptions</property> <value>#(#(#name 'Base VisualWorks' #componentType #bundle))</value> </component-property> <component-property> <name>ModifiersChangeEvent</name> <type>package</type> <property>comment</property> <value>'Adds a support for ModifiersChangeEvent, a special type of MouseEvent issued whenever a keyboard modifier keys change. This event is delivered to the current mouse event handler just as MouseMovedEvent (and not to the current keyboard consumer). The event is ignored (does nothing) by default. The controller can handle it in its #modifiersChangeEvent: The package OVERRIDES the following methods: EventSensor >> eventKeyPress: EventSensor >> eventKeyRelease: '</value> </component-property> <class> <name>ModifiersChangeEvent</name> <environment>UI</environment> <super>UI.MouseEvent</super> <private>false</private> <indexed-type>none</indexed-type> <inst-vars></inst-vars> <class-inst-vars></class-inst-vars> <imports></imports> <category>Interface-Events</category> <attributes> <package>ModifiersChangeEvent</package> </attributes> </class> <comment> <class-id>UI.ModifiersChangeEvent</class-id> <body>ModifiersChangeEvent is a special MouseEvent that is issued whenever a keyboard modifiers change. This enables e.g. an event driven mouse cursor changes based on the keyboard state. </body> </comment> <methods> <class-id>UI.ModifiersChangeEvent class</class-id> <category>prerequisites</category> <body package="ModifiersChangeEvent" selector="hookFor_ModifiersChangeEvent">hookFor_ModifiersChangeEvent "DO NOT DELETE - critical for automatic package dependency calculations."</body> </methods> <methods> <class-id>UI.ModifiersChangeEvent</class-id> <category>dispatching</category> <body package="ModifiersChangeEvent" selector="dispatchTo:">dispatchTo: anObject ^anObject modifiersChangeEvent: self.</body> </methods> <methods> <class-id>UI.ModifiersChangeEvent</class-id> <category>testing</category> <body package="ModifiersChangeEvent" selector="isMotionEvent">isMotionEvent ^true.</body> </methods> <methods> <class-id>UI.Controller</class-id> <category>events</category> <body package="ModifiersChangeEvent" selector="modifiersChangeEvent:">modifiersChangeEvent: aModifiersChangeEvent "Created (as a new method) by ladislav on July 26, 2010. It is a MouseEvent sent whenever a keyboard modifiers change. It is simply a hook the controller can react to." ^nil.</body> </methods> <methods> <class-id>UI.EventSensor</class-id> <category>event processing</category> <body package="ModifiersChangeEvent" selector="eventKeyPress:">eventKeyPress: event "A key on the keyboard has been pressed. Modified by ladislav on July 27, 2010. Added #eventArray: argument to the last message sent." | convertedText keyChar alternative | convertedText := InputManager default retrieveConvertedText: event. (convertedText notNil and: [convertedText size ~= 1]) ifTrue: [convertedText do: [:each | self addMetaInput: ((KeyPressedEvent code: each asCharacter meta: 0) window: window)]. ^self]. keyChar := convertedText isNil ifTrue: [event at: 8] ifFalse: [convertedText at: 1]. alternative := event at: 11. alternative = 0 ifTrue: [alternative := nil]. self keyAt: (event at: 7) character: keyChar alternative: alternative down: true eventArray: event.</body> <body package="ModifiersChangeEvent" selector="eventKeyRelease:">eventKeyRelease: event "A key on the keyboard has been released. Modified by ladislav on July 27, 2010. Added #eventArray: argument to the last message sent." | alternative | alternative := event at: 11. alternative = 0 ifTrue: [alternative := nil]. ^self keyAt: (event at: 7) character: (event at: 8) alternative: alternative down: false eventArray: event.</body> <body package="ModifiersChangeEvent" selector="keyAt:character:alternative:down:eventArray:">keyAt: keyNumber character: aCharacter alternative: alternativeCharacter down: isDownTransition eventArray: anArray "A keyboard key has been pressed or released; take appropriate action. Created (as a new method) by ladislav on July 27, 2010. Extension of #keyAt:character:alternative:down: method that adds support for ModifiersChangeEvent." ^(self state isModifierKey: aCharacter) ifTrue: [ self addMetaInput: (ModifiersChangeEvent withArray: anArray). ] ifFalse: [ self keyAt: keyNumber character: aCharacter alternative: alternativeCharacter down: isDownTransition. ].</body> </methods> <methods> <class-id>UI.SelectionTracker</class-id> <category>events</category> <body package="ModifiersChangeEvent" selector="modifiersChangeEvent:">modifiersChangeEvent: aModifiersChangeEvent "Created (as a new method) by ladislav on July 27, 2010. It is a MouseEvent sent whenever a keyboard modifiers change. It is simply a hook the tracker can react to." ^nil.</body> </methods> </st-source> _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
I'd say knowing if a modified key has changed state is something we could provide up in to the image but the event handler is carefully cross-platform consistent. There are a lot of X11 versions that have no way of providing that information without polling.
Both Windows and OSX can provide it but it's not the same as "the x button was pressed". On OSX it's an API that says "Modifier state was changed" and you have to determine yourself whether you should treat it as a key up / key down type scenario. You don't get key -repeat- events for modifiers either. So making the modifier keys act like regular keys at the image level is a slightly non-trivial task and would require us leaving several of our supported platforms behind in terms of providing the same level of capability. If your requirements aren't quite real time, then waiting for any other kind of input event to inform you and simulating a key press in the image level would work just fine. Michael On Mar 14, 2011, at 1:39 AM, Ladislav Lenart wrote: > Hello, > > we faced the same problem a few months ago. We ended > up with a simple package that adds ModifiersChangeEvent > which is a MouseEvent that informs about modifier key > changes. Note however that the package contains two > overrides (in EventSensor). > > All you have to do is to implement a method > > modifiersChangeEvent: aModifiersChangeEvent > > in your Controller or SelectionTracker subclasses. > > The package is from 7.7 image and dependes only on the > VW base so should work as is. > > > HTH, > > Ladislav Lenart > > > Rick Hedin wrote: >> I am looking at a user interface issue where it might be convenient to detect a press of the control key, by itself. Not ctrl-a. Just press and release of control. Can I detect this using Visual Works Smalltalk? >> Regards, >> Rick >> -- >> I insist on rapport! >> ------------------------------------------------------------------------ >> _______________________________________________ >> vwnc mailing list >> [hidden email] >> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > <?xml version="1.0"?> > > <st-source> > <time-stamp>From VisualWorks®, 7.7 of 15. prosince 2009 on 14. března 2011 at 09:30:05</time-stamp> > > > <component-created> > <name>ModifiersChangeEvent</name> <type>package</type> > </component-created><!-- Package ModifiersChangeEvent(1.1,ladislav)= --> > > > <component-property> > <name>ModifiersChangeEvent</name> <type>package</type> > <property>prerequisiteParcels</property> <value>#(#('Base VisualWorks' ''))</value> > </component-property> > > <component-property> > <name>ModifiersChangeEvent</name> <type>package</type> > <property>developmentPrerequisites</property> <value>#(#(#any 'Base VisualWorks' ''))</value> > </component-property> > > <component-property> > <name>ModifiersChangeEvent</name> <type>package</type> > <property>prerequisiteDescriptions</property> <value>#(#(#name 'Base VisualWorks' #componentType #bundle))</value> > </component-property> > > <component-property> > <name>ModifiersChangeEvent</name> <type>package</type> > <property>comment</property> <value>'Adds a support for ModifiersChangeEvent, a special type of MouseEvent issued whenever a keyboard modifier keys change. This event is delivered to the current mouse event handler just as MouseMovedEvent (and not to the current keyboard consumer). The event is ignored (does nothing) by default. The controller can handle it in its #modifiersChangeEvent: > > The package OVERRIDES the following methods: > EventSensor >> eventKeyPress: > EventSensor >> eventKeyRelease: > '</value> > </component-property> > > <class> > <name>ModifiersChangeEvent</name> > <environment>UI</environment> > <super>UI.MouseEvent</super> > <private>false</private> > <indexed-type>none</indexed-type> > <inst-vars></inst-vars> > <class-inst-vars></class-inst-vars> > <imports></imports> > <category>Interface-Events</category> > <attributes> > <package>ModifiersChangeEvent</package> > </attributes> > </class> > > <comment> > <class-id>UI.ModifiersChangeEvent</class-id> > <body>ModifiersChangeEvent is a special MouseEvent that is issued whenever a keyboard modifiers change. This enables e.g. an event driven mouse cursor changes based on the keyboard state. > </body> > </comment> > > <methods> > <class-id>UI.ModifiersChangeEvent class</class-id> <category>prerequisites</category> > > <body package="ModifiersChangeEvent" selector="hookFor_ModifiersChangeEvent">hookFor_ModifiersChangeEvent > > "DO NOT DELETE - critical for automatic package dependency calculations."</body> > </methods> > > > <methods> > <class-id>UI.ModifiersChangeEvent</class-id> <category>dispatching</category> > > <body package="ModifiersChangeEvent" selector="dispatchTo:">dispatchTo: anObject > > ^anObject modifiersChangeEvent: self.</body> > </methods> > > <methods> > <class-id>UI.ModifiersChangeEvent</class-id> <category>testing</category> > > <body package="ModifiersChangeEvent" selector="isMotionEvent">isMotionEvent > > ^true.</body> > </methods> > > > <methods> > <class-id>UI.Controller</class-id> <category>events</category> > > <body package="ModifiersChangeEvent" selector="modifiersChangeEvent:">modifiersChangeEvent: aModifiersChangeEvent > "Created (as a new method) by ladislav on July 26, 2010. > > It is a MouseEvent sent whenever a keyboard modifiers change. It is simply a hook the controller can react to." > > ^nil.</body> > </methods> > > > <methods> > <class-id>UI.EventSensor</class-id> <category>event processing</category> > > <body package="ModifiersChangeEvent" selector="eventKeyPress:">eventKeyPress: event > "A key on the keyboard has been pressed. > > Modified by ladislav on July 27, 2010. > Added #eventArray: argument to the last message sent." > > | convertedText keyChar alternative | > convertedText := InputManager default retrieveConvertedText: event. > (convertedText notNil and: [convertedText size ~= 1]) ifTrue: > [convertedText do: > [:each | > self addMetaInput: ((KeyPressedEvent code: each asCharacter meta: 0) window: window)]. > ^self]. > keyChar := convertedText isNil > ifTrue: [event at: 8] > ifFalse: [convertedText at: 1]. > alternative := event at: 11. > alternative = 0 ifTrue: [alternative := nil]. > self > keyAt: (event at: 7) > character: keyChar > alternative: alternative > down: true > eventArray: event.</body> > > <body package="ModifiersChangeEvent" selector="eventKeyRelease:">eventKeyRelease: event > "A key on the keyboard has been released. > > Modified by ladislav on July 27, 2010. > Added #eventArray: argument to the last message sent." > > | alternative | > alternative := event at: 11. > alternative = 0 ifTrue: [alternative := nil]. > ^self > keyAt: (event at: 7) > character: (event at: 8) > alternative: alternative > down: false > eventArray: event.</body> > > <body package="ModifiersChangeEvent" selector="keyAt:character:alternative:down:eventArray:">keyAt: keyNumber character: aCharacter alternative: alternativeCharacter down: isDownTransition eventArray: anArray > "A keyboard key has been pressed or released; take appropriate action. > > Created (as a new method) by ladislav on July 27, 2010. > Extension of #keyAt:character:alternative:down: method that adds > support for ModifiersChangeEvent." > > ^(self state isModifierKey: aCharacter) > ifTrue: [ > self addMetaInput: (ModifiersChangeEvent withArray: anArray). > ] > ifFalse: [ > self > keyAt: keyNumber > character: aCharacter > alternative: alternativeCharacter > down: isDownTransition. > ].</body> > </methods> > > > <methods> > <class-id>UI.SelectionTracker</class-id> <category>events</category> > > <body package="ModifiersChangeEvent" selector="modifiersChangeEvent:">modifiersChangeEvent: aModifiersChangeEvent > "Created (as a new method) by ladislav on July 27, 2010. > > It is a MouseEvent sent whenever a keyboard modifiers change. It is simply a hook the tracker can react to." > > ^nil.</body> > </methods> > > > > </st-source> > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Well,
we simply leveraged the functionality already present in the base image, namely InputState>>isModifierKey: aCharacter. The extension works for us on X11 platforms (Debian), Windows XP and 2003 without any issues. But I will keep in mind that if we choose to move to other platform(s), the image might not get the raw event at all. Thx, Ladislav Lenart Michael Lucas-Smith wrote: > I'd say knowing if a modified key has changed state is something we could provide up in to the image but the event handler is carefully cross-platform consistent. There are a lot of X11 versions that have no way of providing that information without polling. > Both Windows and OSX can provide it but it's not the same as "the x button was pressed". On OSX it's an API that says "Modifier state was changed" and you have to determine yourself whether you should treat it as a key up / key down type scenario. You don't get key -repeat- events for modifiers either. > So making the modifier keys act like regular keys at the image level is a slightly non-trivial task and would require us leaving several of our supported platforms behind in terms of providing the same level of capability. > If your requirements aren't quite real time, then waiting for any other kind of input event to inform you and simulating a key press in the image level would work just fine. > > Michael > > On Mar 14, 2011, at 1:39 AM, Ladislav Lenart wrote: > >> Hello, >> >> we faced the same problem a few months ago. We ended >> up with a simple package that adds ModifiersChangeEvent >> which is a MouseEvent that informs about modifier key >> changes. Note however that the package contains two >> overrides (in EventSensor). >> >> All you have to do is to implement a method >> >> modifiersChangeEvent: aModifiersChangeEvent >> >> in your Controller or SelectionTracker subclasses. >> >> The package is from 7.7 image and dependes only on the >> VW base so should work as is. >> >> >> HTH, >> >> Ladislav Lenart >> >> >> Rick Hedin wrote: >>> I am looking at a user interface issue where it might be convenient to detect a press of the control key, by itself. Not ctrl-a. Just press and release of control. Can I detect this using Visual Works Smalltalk? >>> Regards, >>> Rick >>> -- >>> I insist on rapport! >>> ------------------------------------------------------------------------ >>> _______________________________________________ >>> vwnc mailing list >>> [hidden email] >>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc >> <?xml version="1.0"?> >> >> <st-source> >> <time-stamp>From VisualWorks®, 7.7 of 15. prosince 2009 on 14. března 2011 at 09:30:05</time-stamp> >> >> >> <component-created> >> <name>ModifiersChangeEvent</name> <type>package</type> >> </component-created><!-- Package ModifiersChangeEvent(1.1,ladislav)= --> >> >> >> <component-property> >> <name>ModifiersChangeEvent</name> <type>package</type> >> <property>prerequisiteParcels</property> <value>#(#('Base VisualWorks' ''))</value> >> </component-property> >> >> <component-property> >> <name>ModifiersChangeEvent</name> <type>package</type> >> <property>developmentPrerequisites</property> <value>#(#(#any 'Base VisualWorks' ''))</value> >> </component-property> >> >> <component-property> >> <name>ModifiersChangeEvent</name> <type>package</type> >> <property>prerequisiteDescriptions</property> <value>#(#(#name 'Base VisualWorks' #componentType #bundle))</value> >> </component-property> >> >> <component-property> >> <name>ModifiersChangeEvent</name> <type>package</type> >> <property>comment</property> <value>'Adds a support for ModifiersChangeEvent, a special type of MouseEvent issued whenever a keyboard modifier keys change. This event is delivered to the current mouse event handler just as MouseMovedEvent (and not to the current keyboard consumer). The event is ignored (does nothing) by default. The controller can handle it in its #modifiersChangeEvent: >> >> The package OVERRIDES the following methods: >> EventSensor >> eventKeyPress: >> EventSensor >> eventKeyRelease: >> '</value> >> </component-property> >> >> <class> >> <name>ModifiersChangeEvent</name> >> <environment>UI</environment> >> <super>UI.MouseEvent</super> >> <private>false</private> >> <indexed-type>none</indexed-type> >> <inst-vars></inst-vars> >> <class-inst-vars></class-inst-vars> >> <imports></imports> >> <category>Interface-Events</category> >> <attributes> >> <package>ModifiersChangeEvent</package> >> </attributes> >> </class> >> >> <comment> >> <class-id>UI.ModifiersChangeEvent</class-id> >> <body>ModifiersChangeEvent is a special MouseEvent that is issued whenever a keyboard modifiers change. This enables e.g. an event driven mouse cursor changes based on the keyboard state. >> </body> >> </comment> >> >> <methods> >> <class-id>UI.ModifiersChangeEvent class</class-id> <category>prerequisites</category> >> >> <body package="ModifiersChangeEvent" selector="hookFor_ModifiersChangeEvent">hookFor_ModifiersChangeEvent >> >> "DO NOT DELETE - critical for automatic package dependency calculations."</body> >> </methods> >> >> >> <methods> >> <class-id>UI.ModifiersChangeEvent</class-id> <category>dispatching</category> >> >> <body package="ModifiersChangeEvent" selector="dispatchTo:">dispatchTo: anObject >> >> ^anObject modifiersChangeEvent: self.</body> >> </methods> >> >> <methods> >> <class-id>UI.ModifiersChangeEvent</class-id> <category>testing</category> >> >> <body package="ModifiersChangeEvent" selector="isMotionEvent">isMotionEvent >> >> ^true.</body> >> </methods> >> >> >> <methods> >> <class-id>UI.Controller</class-id> <category>events</category> >> >> <body package="ModifiersChangeEvent" selector="modifiersChangeEvent:">modifiersChangeEvent: aModifiersChangeEvent >> "Created (as a new method) by ladislav on July 26, 2010. >> >> It is a MouseEvent sent whenever a keyboard modifiers change. It is simply a hook the controller can react to." >> >> ^nil.</body> >> </methods> >> >> >> <methods> >> <class-id>UI.EventSensor</class-id> <category>event processing</category> >> >> <body package="ModifiersChangeEvent" selector="eventKeyPress:">eventKeyPress: event >> "A key on the keyboard has been pressed. >> >> Modified by ladislav on July 27, 2010. >> Added #eventArray: argument to the last message sent." >> >> | convertedText keyChar alternative | >> convertedText := InputManager default retrieveConvertedText: event. >> (convertedText notNil and: [convertedText size ~= 1]) ifTrue: >> [convertedText do: >> [:each | >> self addMetaInput: ((KeyPressedEvent code: each asCharacter meta: 0) window: window)]. >> ^self]. >> keyChar := convertedText isNil >> ifTrue: [event at: 8] >> ifFalse: [convertedText at: 1]. >> alternative := event at: 11. >> alternative = 0 ifTrue: [alternative := nil]. >> self >> keyAt: (event at: 7) >> character: keyChar >> alternative: alternative >> down: true >> eventArray: event.</body> >> >> <body package="ModifiersChangeEvent" selector="eventKeyRelease:">eventKeyRelease: event >> "A key on the keyboard has been released. >> >> Modified by ladislav on July 27, 2010. >> Added #eventArray: argument to the last message sent." >> >> | alternative | >> alternative := event at: 11. >> alternative = 0 ifTrue: [alternative := nil]. >> ^self >> keyAt: (event at: 7) >> character: (event at: 8) >> alternative: alternative >> down: false >> eventArray: event.</body> >> >> <body package="ModifiersChangeEvent" selector="keyAt:character:alternative:down:eventArray:">keyAt: keyNumber character: aCharacter alternative: alternativeCharacter down: isDownTransition eventArray: anArray >> "A keyboard key has been pressed or released; take appropriate action. >> >> Created (as a new method) by ladislav on July 27, 2010. >> Extension of #keyAt:character:alternative:down: method that adds >> support for ModifiersChangeEvent." >> >> ^(self state isModifierKey: aCharacter) >> ifTrue: [ >> self addMetaInput: (ModifiersChangeEvent withArray: anArray). >> ] >> ifFalse: [ >> self >> keyAt: keyNumber >> character: aCharacter >> alternative: alternativeCharacter >> down: isDownTransition. >> ].</body> >> </methods> >> >> >> <methods> >> <class-id>UI.SelectionTracker</class-id> <category>events</category> >> >> <body package="ModifiersChangeEvent" selector="modifiersChangeEvent:">modifiersChangeEvent: aModifiersChangeEvent >> "Created (as a new method) by ladislav on July 27, 2010. >> >> It is a MouseEvent sent whenever a keyboard modifiers change. It is simply a hook the tracker can react to." >> >> ^nil.</body> >> </methods> >> >> >> >> </st-source> >> _______________________________________________ >> vwnc mailing list >> [hidden email] >> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > > _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Free forum by Nabble | Edit this page |