Results 1 to 18 of 18

Thread: KeyPress problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    KeyPress problem

    I added the KeyPress subroutine to my program so I could detect a keypress and do some special features.

    The problem I am having in when I move the program over to the target system. The program run correctly, but when I do a keypress, nothing happens. It is suppose to open another window on top of the current window, but no window opens.

  2. #2
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: KeyPress problem

    Hi JohnDonaldson,

    How about posting some code ? What version of VB are you using ?
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: KeyPress problem

    Quote Originally Posted by JohnDonaldson
    when I move the program over to the target system
    Move it by copying the exe file, or move it by making a deployment package and installing it on the target system?
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Re: KeyPress problem

    This is the code that is in the form that I am calling from. The form displays a picture that takes the full screen. I then want to popup another form on top buy using a keypress. This works correctly on my development system, but when I move the .exe over to the taget system and run it, the keypress part doesn't work.


    VB Code:
    1. Private Sub Form_Load()
    2.     .
    3.     .
    4.     .
    5.    Me.KeyPreview = True
    6.  
    7. End Sub
    8.  
    9. Private Sub Form_KeyPress(KeyAscii As Integer)
    10.     Dim Toggle As Boolean
    11.    
    12.     If (Chr(KeyAscii) = "s ") And (Not Toggle) Then
    13.         frmCaptureOverlay.Show
    14.         Toggle = True
    15.     ElseIf (Chr(KeyAscii) = " d") And (Toggle) Then
    16.         frmCaptureOverlay.Hide
    17.         Toggle = False
    18.     End If
    19. End Sub

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: KeyPress problem

    For one thing, Toggle is always going to be false. So if you press "d" nothing happens. If you press "s", the overlay will show. Next time nothing happens regardless of the key you press. Change

    Dim Toggle As Boolean
    to
    Static Toggle As Boolean.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Re: KeyPress problem

    I fixed that part by moving "Toggle" to the top of the form and making it global. The problem is that the routine works on the development system. Even if I compile it to a .exe, it still works. The problem is when I move the .exe over to the target system, the program runs OK, but when I press "s" the form does not appear at all. It's like Form_KeyPress doesn't work anymore.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Re: KeyPress problem

    Discovered that Keypress works even on the target system IF it is run from the Main Form. BUT if I try to run KeyPress from any other form, it does not work.

  8. #8
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: KeyPress problem

    The Keypress event only fires for the form that's active. Either add the same code to the other form(s) , read the keyboard state in a timer, or set a hotkey.
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Re: KeyPress problem

    Can you show me a example of how to do the timer or hotkey approach. What I am trying to do is.....display a 1280X1024 image. Then press a key to toggle the menu form to show. Then hit the same key or another key and have it toggle off. The image display form is called from the main form. So the image form is form #2 and the menu form is form #3. Image form sets on top of the main form.

    Hope I explain what I'm doing correctly.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Re: KeyPress problem

    I put the Form_KeyPress code in the Image form. Also put the Me.KeyPreview = true in Image form Form_Load. Ran program. Selected the Image form from Main form. Image form came up. Pressed space bar. menu form did not come up.

    this all works correctly on the development system.

    I have image viewer only program that does not call any other form. It only has the frmMain. The KeyPress routine works great for it. KeyPress on it does a shuttle/jog routine. This is running on the target system.

    Looks like for some reason KeyPress does not work on sub forms, just the main form.

  11. #11
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: KeyPress problem

    Keypress is sometimes fickle, but it should work on all forms. I've attached a quick demo project.
    Attached Files Attached Files
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Re: KeyPress problem

    Keith... Demo works OK, have not tried it on taget system yet. I then modified so keyPress on Form1 calls Form2 and KeyPress on Form2 hides Form2. That worked OK. Then I added Text boxes to Form2, had Form1 send data to the Textboxes when Form2 loads. This works, but when I try to press a key on Form2, Form2 does not hide.

    What I am doing on the target system is a program that the main menu calls a form that has a full scale real time image. Thus no room for buttons and such. I want Keypress on the Image form to call the ImageMenu Form, do what I need on it, then Keypress on the ImageMenu form will then hide ImageMenu. This works on the development system and I even compiled it to a EXE and the EXE runs correctly on the development system. But when I move the EXE over to the target system, Image Form comes up correctly, but when I press a key on the Image Form, ImageMenu form does not come up. Remeber that the Target system ONLY has runtime files and does not have VB6 on it.

    If I can not get this to work, then I am going to create a very smal floating window that will have two buttons on it, "Menu" and "Exit". Menu will then call the ImageMenu form and the "Exit" button on the Imagemenu will hid the ImageForm and the "Exit" button on the Image form will terminate the Image form.
    Last edited by JohnDonaldson; Jun 23rd, 2006 at 10:46 AM.

  13. #13
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: KeyPress problem

    Well, I hope you get it working. I've had similar problem with Keypress. You say that the one form is a full screen image. Is it just a form or is there a picturebox ? If there's a pictureBox, try grabbing it's keypress. IE Picture1_Keypress.

    Good luck, let me know what happens.
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Re: KeyPress problem

    The image is a ActiveX control. I will look and see if it has a keypress inside of it. Thanks for the tip.

  15. #15
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: KeyPress problem

    Quote Originally Posted by JohnDonaldson
    VB Code:
    1. If (Chr(KeyAscii) = "s ") And (Not Toggle) Then
    2.         frmCaptureOverlay.Show
    3.         Toggle = True
    4.     ElseIf (Chr(KeyAscii) = " d") And (Toggle) Then
    5.         frmCaptureOverlay.Hide
    6.         Toggle = False
    7.     End If
    Your problem is that Chr(KeyAscii) will never equal "s " or " d". Remove the spaces, and it should work.

    Personally, I would use Select Case.
    VB Code:
    1. Private Sub Form_KeyPress(KeyAscii As Integer)
    2.   Select Case KeyAscii
    3.   Case 100 ' "d"
    4.     If frmCaptureOverlay.Visible Then
    5.       frmCaptureOverlay.Hide
    6.     End If
    7.   Case 115 ' "s"
    8.     If Not frmCaptureOverlay.Visible Then
    9.       frmCaptureOverlay.Show
    10.     End If
    11.   End Select
    12. End Sub

    The If statements aren't really necessary.

  16. #16
    Addicted Member
    Join Date
    Apr 2006
    Location
    USA
    Posts
    207

    Re: KeyPress problem

    I believe that's just a typo on the forum message. Since, John has repeatedly said that it works on the one computer but not the target PC.

    John ? Is this your problem ?
    Keith_VB6

    If you have any further questions, just ask.
    If this solves things, then please mark the thread resolved.
    [Thread Tools] --> [Mark Thread Resolved]

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Posts
    174

    Re: KeyPress problem

    KEITH......yes I can get keyPress to work on the Development system, but not on the Target system. The target system does not have VB on it, just runtimes.

    I have put Kepress on the Image Window and the ImageMenu Window, It all works on the Developement system but not on the Target system. So I have decided to try a different affroach. Create a floating window with two buttons and use them to call the ImageMenu and exit the Image Window.

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: KeyPress problem

    Quote Originally Posted by JohnDonaldson
    KEITH......yes I can get keyPress to work on the Development system, but not on the Target system. The target system does not have VB on it, just runtimes.
    Did you copy the runtime files, or did you install them with an install package? VB apps don't always work correctly if you just copy the files.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width