Capture keyboard focus for real and true.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Capture keyboard focus for real and true.

Blake-5
Hey, gang:

        So, I've made a morph that responds to keypresses and I've caused it to  
grab the keyboard focus. But if I move the mouse of a workspace, the  
workspace captures the keyboard focus, and from that point forward, my  
morph is back to only responding to keypresses when the mouse is over it.  
My basic question is how to change this. (As long as this morph exists, I  
want it to respond to all keypresses, let's say.)

        It seems like I should be able to hook into the world or into a  
playfield, but I've never been able to figure out how to address an object  
pulled from the catalog. These objects all have names but they only work  
with eToys. Then there's the mysterious number that appears.... So, I  
give: If things are supposed to be done in worlds and playfields, how do  
alter the behavior of those worlds and playfields to meet my needs?

        ===Blake===


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Capture keyboard focus for real and true.

Bert Freudenberg

On Jul 3, 2007, at 0:53 , Blake wrote:

> Hey, gang:
>
> So, I've made a morph that responds to keypresses and I've caused  
> it to grab the keyboard focus. But if I move the mouse of a  
> workspace, the workspace captures the keyboard focus, and from that  
> point forward, my morph is back to only responding to keypresses  
> when the mouse is over it. My basic question is how to change this.  
> (As long as this morph exists, I want it to respond to all  
> keypresses, let's say.)

Send #addKeyboardListener: with your morph as argument to the Hand.  
This way you get all keyboard events independent ot keyboard focus.

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Capture keyboard focus for real and true.

Blake-5
On Mon, 02 Jul 2007 16:06:08 -0700, Bert Freudenberg  
<[hidden email]> wrote:

> Send #addKeyboardListener: with your morph as argument to the Hand. This  
> way you get all keyboard events independent ot keyboard focus.

Well, that's what I thought. In the words of Randy Newman, maybe I'm doing  
it wrong. In my morph class I have:

initialize
    super initialize.
    xDir _ 0.
    yDir _ 0.
    ActiveHand addKeyboardListener: self; keyboardFocus: self.

which is the only reason it works at all. In my keydown method, I have:

keyDown: evt
    self halt.
    (evt keyCharacter = $W) ifTrue: [xDir _ 0. yDir _ -1].
    (evt keyCharacter = $S) ifTrue: [xDir _ 0. yDir _ 1].
    (evt keyCharacter = $D) ifTrue: [xDir _ 1. yDir _ 0].
    (evt keyCharacter = $A) ifTrue: [xDir _ -1. yDir _ 0].
    ^evt

I put in the halt just in case the code was wrong somehow, but if I click  
on any text window, messages stop going to keyDown for my morph.

        ===Blake===
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Capture keyboard focus for real and true.

Bert Freudenberg

On Jul 3, 2007, at 1:23 , Blake wrote:

> On Mon, 02 Jul 2007 16:06:08 -0700, Bert Freudenberg  
> <[hidden email]> wrote:
>
>> Send #addKeyboardListener: with your morph as argument to the  
>> Hand. This way you get all keyboard events independent ot keyboard  
>> focus.
>
> Well, that's what I thought. In the words of Randy Newman, maybe  
> I'm doing it wrong. In my morph class I have:
>
> initialize
>    super initialize.
>    xDir _ 0.
>    yDir _ 0.
>    ActiveHand addKeyboardListener: self; keyboardFocus: self.
>
> which is the only reason it works at all. In my keydown method, I  
> have:
>
> keyDown: evt
>    self halt.
>    (evt keyCharacter = $W) ifTrue: [xDir _ 0. yDir _ -1].
>    (evt keyCharacter = $S) ifTrue: [xDir _ 0. yDir _ 1].
>    (evt keyCharacter = $D) ifTrue: [xDir _ 1. yDir _ 0].
>    (evt keyCharacter = $A) ifTrue: [xDir _ -1. yDir _ 0].
>    ^evt
>
> I put in the halt just in case the code was wrong somehow, but if I  
> click on any text window, messages stop going to keyDown for my morph.

Works for me (though you actually do not need the #keyboardFocus: send).

Note that in Morphic some parts only work with keyStroke events. And  
keyDown/Up events are pretty much neglected, you find almost no  
examples with them.  Besides, up/down codes are platform dependent  
(on my Mac W,A,S,D gives keyValues 13, 0, 1, 2, but they will give  
these codes independent of the keyboard setting so you can be sure it  
refers to the same physical keys).

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Capture keyboard focus for real and true.

Blake-5
On Mon, 02 Jul 2007 16:56:07 -0700, Bert Freudenberg
<[hidden email]> wrote:

> Works for me (though you actually do not need the #keyboardFocus: send).

Without the #keyboardFocus: self, the focus never goes to the newly
created Morph.

So, you're saying that your Morph class gets all keyboard events
regardless of other windows having the focus?

> Note that in Morphic some parts only work with keyStroke events. And  
> keyDown/Up events are pretty much neglected, you find almost no examples  
> with them.  Besides, up/down codes are platform dependent (on my Mac  
> W,A,S,D gives keyValues 13, 0, 1, 2, but they will give these codes  
> independent of the keyboard setting so you can be sure it refers to the  
> same physical keys).

Well, I had suggested that we make a little class for translating
keystrokes across platforms but nobody seemed interested.

In any event, how the heck do I debug =this=
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Capture keyboard focus for real and true.

Bert Freudenberg

On Jul 3, 2007, at 4:39 , Blake wrote:

> On Mon, 02 Jul 2007 16:56:07 -0700, Bert Freudenberg
> <[hidden email]> wrote:
>
>> Works for me (though you actually do not need the #keyboardFocus:  
>> send).
>
> Without the #keyboardFocus: self, the focus never goes to the newly
> created Morph.

Sure, it does not need focus when it is listening anyway.

> So, you're saying that your Morph class gets all keyboard events
> regardless of other windows having the focus?

Sure, that's the idea of listening events in general.

Try the attached file-in. Works for me.

- Bert -




_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

BertKeyMorph.st (795 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Capture keyboard focus for real and true.

Blake-5
On Tue, 03 Jul 2007 01:23:15 -0700, Bert Freudenberg  
<[hidden email]> wrote:

> Try the attached file-in. Works for me.

Yes. OK. Aha. Hmm. (Etc.)

I see the problem. I have this:

handleListenEvent: evt

When I was first making my Morph, I was constantly getting an error  
message about not being able to understand handleListenEvent. So I put it  
in as an empty method.

But if I take it out now, I don't get an error message and the focus issue  
goes away.

So...huh.

http://wiki.squeak.org/squeak/118

        ===Blake===

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Capture keyboard focus for real and true.

Blake-5
In reply to this post by Bert Freudenberg
Bert,

        Thanks a lot, by the way. Your help is much appreciated.

        ===Blake===
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners