DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: Last Key Pressed

  1. #1
    rkbnair Guest

    Last Key Pressed


    How can we trap the lastkey pressed (whether entered tab key or enter key
    etc.) in the LostFocus event of a control?


  2. #2
    Phil Weber Guest

    Re: Last Key Pressed

    > How can we trap the lastkey pressed (whether entered
    > Tab or Enter key, etc.) in the LostFocus event of a control?


    RK: Why do you want to? What are you trying to accomplish? There's probably
    a cleaner way to do it.
    ---
    Phil Weber



  3. #3
    rkbnair Guest

    Re: Last Key Pressed


    Phil,
    I have a sstab object (MS tab page) and when I press enter key on the last
    field in the first tab page, I want to goto the next tab page. So, I want
    to write this code in the lostfocus event of the last field in the first
    tab page.


    Please advise me the clean way of doing it.

    Thanks

    "Phil Weber" <pweber@devx.com> wrote:
    > > How can we trap the lastkey pressed (whether entered
    > > Tab or Enter key, etc.) in the LostFocus event of a control?

    >
    >RK: Why do you want to? What are you trying to accomplish? There's probably
    >a cleaner way to do it.
    >---
    >Phil Weber
    >
    >



  4. #4
    Daryl M Guest

    Re: Last Key Pressed

    If you want to follow standard Windows GUI guidelines, you shouldn't be
    doing this. The standard is that the Tab key will only cycle through the
    fields on the current tab. The user should click the next tab (or use an
    Alt-key assignment for the tab) to access that tab.

    If you really want to go to the next tab, you could do it in the LostFocus
    event of the last field on the tab. Depending on the tab control you are
    using, you will have to activate the correct tab, and then use SetFocus to
    set the focus to the first field on the tab. However, there are several
    things you should consider. For example, what if the last field on a tab has
    the focus, and then the user clicks the Cancel button to close the form. In
    this case you wouldn't want to set the focus to the next tab since the user
    wants to close the form. Also, if you are tabbing forward, then you should
    also consider Shift-Tab where the user is backing up. Then if the first
    field on the tab has the focus, if Shift-Tab is pressed then the previous
    tab should be activated and focus set to the last field on that tab.

    For the effort involved, I would recommend sticking with the Windows
    standard and not switch tabs based on LostFocus.


    "rkbnair" <rkannale@solus1.oceaneering.com> wrote in message
    news:39996016$1@news.devx.com...
    >
    > Phil,
    > I have a sstab object (MS tab page) and when I press enter key on the last
    > field in the first tab page, I want to goto the next tab page. So, I want
    > to write this code in the lostfocus event of the last field in the first
    > tab page.
    >
    >
    > Please advise me the clean way of doing it.
    >
    > Thanks
    >
    > "Phil Weber" <pweber@devx.com> wrote:
    > > > How can we trap the lastkey pressed (whether entered
    > > > Tab or Enter key, etc.) in the LostFocus event of a control?

    > >
    > >RK: Why do you want to? What are you trying to accomplish? There's

    probably
    > >a cleaner way to do it.
    > >---
    > >Phil Weber
    > >
    > >

    >




  5. #5
    rkbnair Guest

    Re: Last Key Pressed


    Thanks Daryl. I highly appreciate u'r efforts to give some guidelines regarding
    this.
    You have mentioned that, by default, when the tab key is pressed on the
    last field, the focus changes to the first field in the same tab. However,
    in my case, it goes to the next field in the next tab even though the current
    tab is the first one. Is this built in this way OR should I set the tab using
    taborder.vbp?

    Thanks again,
    RK.

    "Daryl M" <darylm4290@aol.com> wrote:
    >If you want to follow standard Windows GUI guidelines, you shouldn't be
    >doing this. The standard is that the Tab key will only cycle through the
    >fields on the current tab. The user should click the next tab (or use an
    >Alt-key assignment for the tab) to access that tab.
    >
    >If you really want to go to the next tab, you could do it in the LostFocus
    >event of the last field on the tab. Depending on the tab control you are
    >using, you will have to activate the correct tab, and then use SetFocus

    to
    >set the focus to the first field on the tab. However, there are several
    >things you should consider. For example, what if the last field on a tab

    has
    >the focus, and then the user clicks the Cancel button to close the form.

    In
    >this case you wouldn't want to set the focus to the next tab since the user
    >wants to close the form. Also, if you are tabbing forward, then you should
    >also consider Shift-Tab where the user is backing up. Then if the first
    >field on the tab has the focus, if Shift-Tab is pressed then the previous
    >tab should be activated and focus set to the last field on that tab.
    >
    >For the effort involved, I would recommend sticking with the Windows
    >standard and not switch tabs based on LostFocus.
    >
    >
    >"rkbnair" <rkannale@solus1.oceaneering.com> wrote in message
    >news:39996016$1@news.devx.com...
    >>
    >> Phil,
    >> I have a sstab object (MS tab page) and when I press enter key on the

    last
    >> field in the first tab page, I want to goto the next tab page. So, I want
    >> to write this code in the lostfocus event of the last field in the first
    >> tab page.
    >>
    >>
    >> Please advise me the clean way of doing it.
    >>
    >> Thanks
    >>
    >> "Phil Weber" <pweber@devx.com> wrote:
    >> > > How can we trap the lastkey pressed (whether entered
    >> > > Tab or Enter key, etc.) in the LostFocus event of a control?
    >> >
    >> >RK: Why do you want to? What are you trying to accomplish? There's

    >probably
    >> >a cleaner way to do it.
    >> >---
    >> >Phil Weber
    >> >
    >> >

    >>

    >
    >



  6. #6
    Daryl M Guest

    Re: Last Key Pressed

    Which tab control are you using? I use a 3rd party control called Tab Pro,
    and this control does not have this behavior. I remember having a similar
    problem when using the tab control that comes with vb. If I was on the last
    field of a tab, pressing tab would move the focus to then first field on the
    next tab, although the next tab would not be activated, so it appeared that
    the cursor would just disappear. What I ended up doing was putting a frame
    on each tab and then put the controls for that tab in the frame and set each
    frame's enabled property to False. In the tab activate event, I would then
    set the enabled property for the frame for the active tab to True, and all
    other tabs to False. That would then prevent fields on the other tabs from
    receiving the focus until the tab was activated.


    "rkbnair" <rkannale@solus1.oceaneering.com> wrote in message
    news:399aa508$1@news.devx.com...
    >
    > Thanks Daryl. I highly appreciate u'r efforts to give some guidelines

    regarding
    > this.
    > You have mentioned that, by default, when the tab key is pressed on the
    > last field, the focus changes to the first field in the same tab. However,
    > in my case, it goes to the next field in the next tab even though the

    current
    > tab is the first one. Is this built in this way OR should I set the tab

    using
    > taborder.vbp?
    >
    > Thanks again,
    > RK.
    >
    > "Daryl M" <darylm4290@aol.com> wrote:
    > >If you want to follow standard Windows GUI guidelines, you shouldn't be
    > >doing this. The standard is that the Tab key will only cycle through the
    > >fields on the current tab. The user should click the next tab (or use an
    > >Alt-key assignment for the tab) to access that tab.
    > >
    > >If you really want to go to the next tab, you could do it in the

    LostFocus
    > >event of the last field on the tab. Depending on the tab control you are
    > >using, you will have to activate the correct tab, and then use SetFocus

    > to
    > >set the focus to the first field on the tab. However, there are several
    > >things you should consider. For example, what if the last field on a tab

    > has
    > >the focus, and then the user clicks the Cancel button to close the form.

    > In
    > >this case you wouldn't want to set the focus to the next tab since the

    user
    > >wants to close the form. Also, if you are tabbing forward, then you

    should
    > >also consider Shift-Tab where the user is backing up. Then if the first
    > >field on the tab has the focus, if Shift-Tab is pressed then the previous
    > >tab should be activated and focus set to the last field on that tab.
    > >
    > >For the effort involved, I would recommend sticking with the Windows
    > >standard and not switch tabs based on LostFocus.
    > >
    > >
    > >"rkbnair" <rkannale@solus1.oceaneering.com> wrote in message
    > >news:39996016$1@news.devx.com...
    > >>
    > >> Phil,
    > >> I have a sstab object (MS tab page) and when I press enter key on the

    > last
    > >> field in the first tab page, I want to goto the next tab page. So, I

    want
    > >> to write this code in the lostfocus event of the last field in the

    first
    > >> tab page.
    > >>
    > >>
    > >> Please advise me the clean way of doing it.
    > >>
    > >> Thanks
    > >>
    > >> "Phil Weber" <pweber@devx.com> wrote:
    > >> > > How can we trap the lastkey pressed (whether entered
    > >> > > Tab or Enter key, etc.) in the LostFocus event of a control?
    > >> >
    > >> >RK: Why do you want to? What are you trying to accomplish? There's

    > >probably
    > >> >a cleaner way to do it.
    > >> >---
    > >> >Phil Weber
    > >> >
    > >> >
    > >>

    > >
    > >

    >




  7. #7
    rkbnair Guest

    Re: Last Key Pressed


    Daryl, Thanks very muh. Yes I'm using the same control (Microsoft Tabbed dialog
    control) The problem is exactly as u experienced before.

    BTW There is no activate event in that control. Will gotfocus do the same?

    Thanks

    "Daryl M" <darylm4290@aol.com> wrote:
    >Which tab control are you using? I use a 3rd party control called Tab Pro,
    >and this control does not have this behavior. I remember having a similar
    >problem when using the tab control that comes with vb. If I was on the last
    >field of a tab, pressing tab would move the focus to then first field on

    the
    >next tab, although the next tab would not be activated, so it appeared that
    >the cursor would just disappear. What I ended up doing was putting a frame
    >on each tab and then put the controls for that tab in the frame and set

    each
    >frame's enabled property to False. In the tab activate event, I would then
    >set the enabled property for the frame for the active tab to True, and all
    >other tabs to False. That would then prevent fields on the other tabs from
    >receiving the focus until the tab was activated.
    >
    >
    >"rkbnair" <rkannale@solus1.oceaneering.com> wrote in message
    >news:399aa508$1@news.devx.com...
    >>
    >> Thanks Daryl. I highly appreciate u'r efforts to give some guidelines

    >regarding
    >> this.
    >> You have mentioned that, by default, when the tab key is pressed on the
    >> last field, the focus changes to the first field in the same tab. However,
    >> in my case, it goes to the next field in the next tab even though the

    >current
    >> tab is the first one. Is this built in this way OR should I set the tab

    >using
    >> taborder.vbp?
    >>
    >> Thanks again,
    >> RK.
    >>
    >> "Daryl M" <darylm4290@aol.com> wrote:
    >> >If you want to follow standard Windows GUI guidelines, you shouldn't

    be
    >> >doing this. The standard is that the Tab key will only cycle through

    the
    >> >fields on the current tab. The user should click the next tab (or use

    an
    >> >Alt-key assignment for the tab) to access that tab.
    >> >
    >> >If you really want to go to the next tab, you could do it in the

    >LostFocus
    >> >event of the last field on the tab. Depending on the tab control you

    are
    >> >using, you will have to activate the correct tab, and then use SetFocus

    >> to
    >> >set the focus to the first field on the tab. However, there are several
    >> >things you should consider. For example, what if the last field on a

    tab
    >> has
    >> >the focus, and then the user clicks the Cancel button to close the form.

    >> In
    >> >this case you wouldn't want to set the focus to the next tab since the

    >user
    >> >wants to close the form. Also, if you are tabbing forward, then you

    >should
    >> >also consider Shift-Tab where the user is backing up. Then if the first
    >> >field on the tab has the focus, if Shift-Tab is pressed then the previous
    >> >tab should be activated and focus set to the last field on that tab.
    >> >
    >> >For the effort involved, I would recommend sticking with the Windows
    >> >standard and not switch tabs based on LostFocus.
    >> >
    >> >
    >> >"rkbnair" <rkannale@solus1.oceaneering.com> wrote in message
    >> >news:39996016$1@news.devx.com...
    >> >>
    >> >> Phil,
    >> >> I have a sstab object (MS tab page) and when I press enter key on the

    >> last
    >> >> field in the first tab page, I want to goto the next tab page. So,

    I
    >want
    >> >> to write this code in the lostfocus event of the last field in the

    >first
    >> >> tab page.
    >> >>
    >> >>
    >> >> Please advise me the clean way of doing it.
    >> >>
    >> >> Thanks
    >> >>
    >> >> "Phil Weber" <pweber@devx.com> wrote:
    >> >> > > How can we trap the lastkey pressed (whether entered
    >> >> > > Tab or Enter key, etc.) in the LostFocus event of a control?
    >> >> >
    >> >> >RK: Why do you want to? What are you trying to accomplish? There's
    >> >probably
    >> >> >a cleaner way to do it.
    >> >> >---
    >> >> >Phil Weber
    >> >> >
    >> >> >
    >> >>
    >> >
    >> >

    >>

    >
    >



  8. #8
    Daryl M Guest

    Re: Last Key Pressed

    No, you don't want to use the GotFocus event for this. You should use the
    Click event. If you use a control array for your frames and use the same
    index value for the frames as the associated tab number (frame index for
    Tab0 is 0, index for Tab1 is 1, etc.) then you can use something similar to
    the following code in the Click event.

    Private Sub SSTab1_Click(PreviousTab As Integer)
    Frame1(PreviousTab).Enabled = False
    Frame1(SSTab1.Tab).Enabled = True
    End Sub




    "rkbnair" <rkannale@solus1.oceaneering.com> wrote in message
    news:399adbd7$1@news.devx.com...
    >
    > Daryl, Thanks very muh. Yes I'm using the same control (Microsoft Tabbed

    dialog
    > control) The problem is exactly as u experienced before.
    >
    > BTW There is no activate event in that control. Will gotfocus do the same?
    >
    > Thanks
    >
    > "Daryl M" <darylm4290@aol.com> wrote:
    > >Which tab control are you using? I use a 3rd party control called Tab

    Pro,
    > >and this control does not have this behavior. I remember having a similar
    > >problem when using the tab control that comes with vb. If I was on the

    last
    > >field of a tab, pressing tab would move the focus to then first field on

    > the
    > >next tab, although the next tab would not be activated, so it appeared

    that
    > >the cursor would just disappear. What I ended up doing was putting a

    frame
    > >on each tab and then put the controls for that tab in the frame and set

    > each
    > >frame's enabled property to False. In the tab activate event, I would

    then
    > >set the enabled property for the frame for the active tab to True, and

    all
    > >other tabs to False. That would then prevent fields on the other tabs

    from
    > >receiving the focus until the tab was activated.
    > >
    > >
    > >"rkbnair" <rkannale@solus1.oceaneering.com> wrote in message
    > >news:399aa508$1@news.devx.com...
    > >>
    > >> Thanks Daryl. I highly appreciate u'r efforts to give some guidelines

    > >regarding
    > >> this.
    > >> You have mentioned that, by default, when the tab key is pressed on

    the
    > >> last field, the focus changes to the first field in the same tab.

    However,
    > >> in my case, it goes to the next field in the next tab even though the

    > >current
    > >> tab is the first one. Is this built in this way OR should I set the tab

    > >using
    > >> taborder.vbp?
    > >>
    > >> Thanks again,
    > >> RK.
    > >>
    > >> "Daryl M" <darylm4290@aol.com> wrote:
    > >> >If you want to follow standard Windows GUI guidelines, you shouldn't

    > be
    > >> >doing this. The standard is that the Tab key will only cycle through

    > the
    > >> >fields on the current tab. The user should click the next tab (or use

    > an
    > >> >Alt-key assignment for the tab) to access that tab.
    > >> >
    > >> >If you really want to go to the next tab, you could do it in the

    > >LostFocus
    > >> >event of the last field on the tab. Depending on the tab control you

    > are
    > >> >using, you will have to activate the correct tab, and then use

    SetFocus
    > >> to
    > >> >set the focus to the first field on the tab. However, there are

    several
    > >> >things you should consider. For example, what if the last field on a

    > tab
    > >> has
    > >> >the focus, and then the user clicks the Cancel button to close the

    form.
    > >> In
    > >> >this case you wouldn't want to set the focus to the next tab since the

    > >user
    > >> >wants to close the form. Also, if you are tabbing forward, then you

    > >should
    > >> >also consider Shift-Tab where the user is backing up. Then if the

    first
    > >> >field on the tab has the focus, if Shift-Tab is pressed then the

    previous
    > >> >tab should be activated and focus set to the last field on that tab.
    > >> >
    > >> >For the effort involved, I would recommend sticking with the Windows
    > >> >standard and not switch tabs based on LostFocus.
    > >> >
    > >> >
    > >> >"rkbnair" <rkannale@solus1.oceaneering.com> wrote in message
    > >> >news:39996016$1@news.devx.com...
    > >> >>
    > >> >> Phil,
    > >> >> I have a sstab object (MS tab page) and when I press enter key on

    the
    > >> last
    > >> >> field in the first tab page, I want to goto the next tab page. So,

    > I
    > >want
    > >> >> to write this code in the lostfocus event of the last field in the

    > >first
    > >> >> tab page.
    > >> >>
    > >> >>
    > >> >> Please advise me the clean way of doing it.
    > >> >>
    > >> >> Thanks
    > >> >>
    > >> >> "Phil Weber" <pweber@devx.com> wrote:
    > >> >> > > How can we trap the lastkey pressed (whether entered
    > >> >> > > Tab or Enter key, etc.) in the LostFocus event of a control?
    > >> >> >
    > >> >> >RK: Why do you want to? What are you trying to accomplish? There's
    > >> >probably
    > >> >> >a cleaner way to do it.
    > >> >> >---
    > >> >> >Phil Weber
    > >> >> >
    > >> >> >
    > >> >>
    > >> >
    > >> >
    > >>

    > >
    > >

    >




  9. #9
    rkbnair Guest

    Re: Last Key Pressed


    PERFECT....Thanks Daryl.

    RK.

    "Daryl M" <darylm4290@aol.com> wrote:
    >No, you don't want to use the GotFocus event for this. You should use the
    >Click event. If you use a control array for your frames and use the same
    >index value for the frames as the associated tab number (frame index for
    >Tab0 is 0, index for Tab1 is 1, etc.) then you can use something similar

    to
    >the following code in the Click event.
    >
    >Private Sub SSTab1_Click(PreviousTab As Integer)
    > Frame1(PreviousTab).Enabled = False
    > Frame1(SSTab1.Tab).Enabled = True
    >End Sub
    >
    >
    >
    >
    >"rkbnair" <rkannale@solus1.oceaneering.com> wrote in message
    >news:399adbd7$1@news.devx.com...
    >>
    >> Daryl, Thanks very muh. Yes I'm using the same control (Microsoft Tabbed

    >dialog
    >> control) The problem is exactly as u experienced before.
    >>
    >> BTW There is no activate event in that control. Will gotfocus do the same?
    >>
    >> Thanks
    >>
    >> "Daryl M" <darylm4290@aol.com> wrote:
    >> >Which tab control are you using? I use a 3rd party control called Tab

    >Pro,
    >> >and this control does not have this behavior. I remember having a similar
    >> >problem when using the tab control that comes with vb. If I was on the

    >last
    >> >field of a tab, pressing tab would move the focus to then first field

    on
    >> the
    >> >next tab, although the next tab would not be activated, so it appeared

    >that
    >> >the cursor would just disappear. What I ended up doing was putting a

    >frame
    >> >on each tab and then put the controls for that tab in the frame and set

    >> each
    >> >frame's enabled property to False. In the tab activate event, I would

    >then
    >> >set the enabled property for the frame for the active tab to True, and

    >all
    >> >other tabs to False. That would then prevent fields on the other tabs

    >from
    >> >receiving the focus until the tab was activated.
    >> >
    >> >
    >> >"rkbnair" <rkannale@solus1.oceaneering.com> wrote in message
    >> >news:399aa508$1@news.devx.com...
    >> >>
    >> >> Thanks Daryl. I highly appreciate u'r efforts to give some guidelines
    >> >regarding
    >> >> this.
    >> >> You have mentioned that, by default, when the tab key is pressed on

    >the
    >> >> last field, the focus changes to the first field in the same tab.

    >However,
    >> >> in my case, it goes to the next field in the next tab even though the
    >> >current
    >> >> tab is the first one. Is this built in this way OR should I set the

    tab
    >> >using
    >> >> taborder.vbp?
    >> >>
    >> >> Thanks again,
    >> >> RK.
    >> >>
    >> >> "Daryl M" <darylm4290@aol.com> wrote:
    >> >> >If you want to follow standard Windows GUI guidelines, you shouldn't

    >> be
    >> >> >doing this. The standard is that the Tab key will only cycle through

    >> the
    >> >> >fields on the current tab. The user should click the next tab (or

    use
    >> an
    >> >> >Alt-key assignment for the tab) to access that tab.
    >> >> >
    >> >> >If you really want to go to the next tab, you could do it in the
    >> >LostFocus
    >> >> >event of the last field on the tab. Depending on the tab control you

    >> are
    >> >> >using, you will have to activate the correct tab, and then use

    >SetFocus
    >> >> to
    >> >> >set the focus to the first field on the tab. However, there are

    >several
    >> >> >things you should consider. For example, what if the last field on

    a
    >> tab
    >> >> has
    >> >> >the focus, and then the user clicks the Cancel button to close the

    >form.
    >> >> In
    >> >> >this case you wouldn't want to set the focus to the next tab since

    the
    >> >user
    >> >> >wants to close the form. Also, if you are tabbing forward, then you
    >> >should
    >> >> >also consider Shift-Tab where the user is backing up. Then if the

    >first
    >> >> >field on the tab has the focus, if Shift-Tab is pressed then the

    >previous
    >> >> >tab should be activated and focus set to the last field on that tab.
    >> >> >
    >> >> >For the effort involved, I would recommend sticking with the Windows
    >> >> >standard and not switch tabs based on LostFocus.
    >> >> >
    >> >> >
    >> >> >"rkbnair" <rkannale@solus1.oceaneering.com> wrote in message
    >> >> >news:39996016$1@news.devx.com...
    >> >> >>
    >> >> >> Phil,
    >> >> >> I have a sstab object (MS tab page) and when I press enter key on

    >the
    >> >> last
    >> >> >> field in the first tab page, I want to goto the next tab page. So,

    >> I
    >> >want
    >> >> >> to write this code in the lostfocus event of the last field in the
    >> >first
    >> >> >> tab page.
    >> >> >>
    >> >> >>
    >> >> >> Please advise me the clean way of doing it.
    >> >> >>
    >> >> >> Thanks
    >> >> >>
    >> >> >> "Phil Weber" <pweber@devx.com> wrote:
    >> >> >> > > How can we trap the lastkey pressed (whether entered
    >> >> >> > > Tab or Enter key, etc.) in the LostFocus event of a control?
    >> >> >> >
    >> >> >> >RK: Why do you want to? What are you trying to accomplish? There's
    >> >> >probably
    >> >> >> >a cleaner way to do it.
    >> >> >> >---
    >> >> >> >Phil Weber
    >> >> >> >
    >> >> >> >
    >> >> >>
    >> >> >
    >> >> >
    >> >>
    >> >
    >> >

    >>

    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center