Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keyPress event while another app run 1

Status
Not open for further replies.

nivini

Programmer
Mar 24, 2004
64
Hi All
I need to use keypress event while the ppt file run, in order to change to another ppt file. In short , what the code suppose to do is that: when a user press key 49 (that's '1') pp1.ppt start running, if the user want to stop pp1.ppt and start pp2.ppt he press '2' , and the other way round.
The code below gives me the right ppt file running, but the second keypress event is 'useless' since on the screen there's the ppt file run.
Now, how can i jump from one ppt file to another, with the keypress event?

Code:
Option Explicit
Option Base 1
Dim objPP As PowerPoint.Application
--------------------------------------
Private Sub Form_KeyPress(KeyAscii As Integer)

Set objPP = New PowerPoint.Application
Dim PP As PowerPoint.Presentation
Dim str As String
DoEvents

Set objPP = New PowerPoint.Application
objPP.Visible = True

Select Case KeyAscii
Case 49
  str = "D:\PP\ppt1.ppt"
Case 50
  str = "D:\PP\pp2.ppt"
End Select

Set PP = objPP.Presentations.Open(str, True)
With PP
    .SlideShowSettings.Run
End With

End Sub

I mailed this question before, but got no answer, and i do need the help badly
TIA
Nivini
 
The problem is that KeyPress is an event that will only occur when your application form has focus. What you need to do is bring it to the front, somehow...

Have a look at these API calls in user32.dll:

Code:
SetWindowPos Lib "user32.dll" (byval hWnd as long, _
                                byval hWndInsertAfter as long, _
                                byval X as long, _
                                byval Y as long, _
                                byval cX as long, _
                                byval cY as long, _
                                byval wFlags as long) as long

Code:
SetForegroundWindow Lib "user32.dll" (byval hWnd as long) as long

Code:
SetFocusAPI lib "user32.dll" alias "SetFocus" (byval hWnd as long) as long

I've had a quick play with them and I can't quite get them to do what you want, but you might have better luck...


Paul
 
Thanks Paul
I'll give it a try
N
 
What you want to do is use the GetAsyncKeyState in a sub Main proceedure or a timer, to check the value of a hotkey.

This allows you to have your window out of focus or even minimized, and the key will still work.

Code:
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Public Sub Main()

If GetAsyncKeyState(vbKeyF11) And &H8000 Then
    ' F11 key was pressed.  Do something here...

End If

End Sub

This should give you the general idea on what to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top