 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Bartimus
Joined: 10 Nov 2005 Posts: 164 Location: Texas
|
Posted: Tue Feb 02, 2010 5:22 pm Post subject: Trouble with A_GuiEvent, please look |
|
|
I'm trying to make a video directory of sorts that will easily list what videos are in a specific folder and play them. Please check out the code: | Code: | VideoList:
Gui +ToolWindow
gui, font, s26, Verdana
Gui, Color, 000050
Gui, Add, Picture, w298 h-1 x0 y0, gPoster
Gui, Add, ListView, Background000050 cWhite -E0x200 -Multi -hdr Sort x300 y2 r11 w700 gMyListView,Video Title
LV_ModifyCol(1,700)
Gui, Show, w1000 h540, Video Directory
Loop
{
ifnotexist, %DrvLtr%:\Portable
{
Gui,Destroy
Goto DriveDetect
}
Gui, Show, NA w1004 h540, Video Directory
; Gather a list of file names from a folder and put them into the ListView:
Loop, %DrvLtr%:\Portable\*.avi
LV_Add("", A_LoopFileName)
Loop, %DrvLtr%:\Portable\*.wmv
LV_Add("", A_LoopFileName)
Sleep, 60000
LV_Delete()
}
return
MyListView:
;If a title is selected by either using the arrow keys to scroll or by a SingleClick, show movie's poster
if A_GuiEvent = SingleClick
{
LV_GetText(RowText, A_EventInfo) ; Get the text from the row's first field.
GuiControl,, Poster, %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg
;Following is for troubleshooting purpose
IfExist %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg
PosterIs = It's there
TrayTip,Video Directory, Poster: %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg`nIs it there? %PosterIs%
PosterIs = It's NOT there
}
;if the ENTER Key is pressed, start a movie
if A_GuiEvent = ENTER
{
LV_GetText(RowText, A_EventInfo) ; Get the text from the row's first field.
TrayTip,Video Directory, Starting: "%DrvLtr%:\Portable\%RowText%"
Run, %DrvLtr%:\Portable\%RowText%, Max
}
;if a title is DoubleClicked, start a movie
if A_GuiEvent = DoubleClick
{
LV_GetText(RowText, A_EventInfo) ; Get the text from the row's first field.
TrayTip,Video Directory, Starting: "%DrvLtr%:\Portable\%RowText%"
Run, %DrvLtr%:\Portable\%RowText%, Max
}
Return
GuiClose:
ExitApp |
Now... this works. If I double click on any given title, the video will play, but I want it to do more. I want it to show an image for each video that I either single click on or scroll down to with the arrow keys. I also want to be able to press the ENTER key instead of double clicking to start a video.
Can anyone tell me what I've done wrong?
Thanks |
|
| Back to top |
|
 |
flyingDman
Joined: 27 Feb 2009 Posts: 690 Location: Burbank, California
|
Posted: Tue Feb 02, 2010 7:06 pm Post subject: |
|
|
A couple of things:
to show your jpg change your code to:
| Code: | | Gui, Add, Picture, w298 h-1 x0 y0 vPoster ;note the v |
then for the click, double click or arrow up/down action use something like:
| Code: | MyListView:
if (a_guievent = "K") OR (A_GuiEvent = "Normal")
{
tmprw:=LV_GetNext("","F")
LV_GetText(RowText, tmprw) ; Get the text from the row's first field.
run, %dfltfldr%\%RowText%, , Max
StringTrimRight, RowText, RowText, 4
GuiControl,, Poster, %dfltfldr%\Movie Posters\%RowText%.jpg
}
Return |
_________________ "Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data... |
|
| Back to top |
|
 |
flyingDman
Joined: 27 Feb 2009 Posts: 690 Location: Burbank, California
|
Posted: Tue Feb 02, 2010 7:34 pm Post subject: |
|
|
to ignore non-navigation keys in the "guievent" use:
| Code: | | if (a_guievent = "K" && (a_eventinfo = 33 || a_eventinfo = 34 || a_eventinfo = 35 || a_eventinfo = 36 || a_eventinfo = 38 || a_eventinfo = 40)) OR (A_GuiEvent = "Normal") |
page up is 33
page down is 34
arrow up is 38
arrow down is 40
home is 36
end is 35 _________________ "Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data... |
|
| Back to top |
|
 |
Bartimus
Joined: 10 Nov 2005 Posts: 164 Location: Texas
|
Posted: Wed Feb 03, 2010 6:03 pm Post subject: |
|
|
Here is my new and improved code: | Code: | VideoList:
RowText = no file.jpg
Gui -Border
gui, font, s13, Verdana
Gui, Add, Button, w98 x600 y0, Re&fresh
Gui, Add, Button, w98 x700 y0, Re&Boot
Gui, Add, Button, w98 x800 y0, &Hibernate
Gui, Add, Button, w98 x900 y0, &Exit
gui, font, s30, Verdana
Gui, Color, 000050
Gui, Add, ListView, Background000050 cWhite -E0x200 AltSubmit -Multi -hdr Sort x300 y35 r9 w725 gMyListView,Video Title
gui, font, s8, Verdana
Gui, Add, Text, cGray w550 x2 y1 vSelectedFile,File: none
Gui, Add, Picture, x5 y35 vPoster
LV_ModifyCol(1,725)
Gui, Show, NA w1004 h450, Video Directory
AddTitles:
Loop, %DrvLtr%:\Portable\*.avi
LV_Add("", A_LoopFileName)
Loop, %DrvLtr%:\Portable\*.wmv
LV_Add("", A_LoopFileName)
Loop
{
ifnotexist, %DrvLtr%:\Portable
{
Gui,Destroy
Goto DriveDetect
}
}
return
MyListView:
TrayTip, Video Directory, Event type: %A_GuiEvent%
if (a_guievent = "K") OR (A_GuiEvent = "Normal")
{
tmprw:=LV_GetNext("","F")
LV_GetText(RowText, tmprw) ; Get the text from the row's first field.
;StringTrimRight, RowText, RowText, 4
ifexist %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg
IsIt = Does Exist
; TrayTip, Video Directory, File: %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg`n%IsIt%
IsIt =
GuiControl,, Poster, %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg
GuiControl,, SelectedFIle, File: %DrvLtr%:\Portable\Movie Posters\%RowText%.jpg
}
if (a_guievent = 13) OR (A_GuiEvent = "DoubleClick")
run, %DrvLtr%:\Portable\%RowText%, , Max
Return
ButtonRefresh:
LV_Delete()
Goto, AddTitles
ButtonReboot:
Shutdown, 2
MsgBox, Video Directory, Rebooting the system.
ExitApp
ButtonHibernate:
; Call the Windows API function "SetSuspendState" to have the system suspend or hibernate.
; Windows 95/NT4: Since this function does not exist, the following call would have no effect.
; Parameter #1: Pass 1 instead of 0 to hibernate rather than suspend.
; Parameter #2: Pass 1 instead of 0 to suspend immediately rather than asking each application for permission.
; Parameter #3: Pass 1 instead of 0 to disable all wake events.
DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
MsgBox, Video Directory, Hibernating the system.
return
ButtonExit:
GuiClose:
ExitApp |
All works great except for the stinkin ENTER key doesn't register as an event. Does anybody have a solution |
|
| Back to top |
|
 |
closed
Joined: 07 Feb 2008 Posts: 509
|
Posted: Wed Feb 03, 2010 7:42 pm Post subject: |
|
|
from the helpfile topic ListView G-label Notifications
| Quote: |
However, the Enter keystroke is not received; to receive it, use a default button as described below.
To detect when the user has pressed Enter while a ListView has focus, use a default button (which can be hidden if desired). For example:
|
| Code: |
Gui, Add, Button, Hidden Default, OK
...
ButtonOK:
GuiControlGet, FocusedControl, FocusV
if FocusedControl <> MyListView
return
MsgBox % "Enter was pressed. The focused row number is " . LV_GetNext(0, "Focused")
return |
|
|
| Back to top |
|
 |
flyingDman
Joined: 27 Feb 2009 Posts: 690 Location: Burbank, California
|
Posted: Thu Feb 04, 2010 3:30 am Post subject: |
|
|
If Mylistview does not have the focus, the Enter key will not do anything. In order for the listview to regain focus use:
| Code: | ButtonOK:
ControlFocus, SysListView321, Video Directory
focusedrow := LV_GetNext(0, "Focused")
run, %DrvLtr%:\Portable\%focusedrow%, Max
return |
obviously nothing happens if no row has the focus.
If Mylistview does have the focus, pressing enter does not do anything unless a row has the focus. If one of the rows has the focus, it got that focus by getting a (double) mouse click or after an arrow/page up/down and the run, ... code was already executed.
In other words, the Enter key has limited use. A better way imho is to give the listview the focus and leave the focus there. I.e. do not allow the other controls to get the focus. Use "-tabstop" for buttons and edit controls, and include code to have the listview regain the focus.
I have a small image viewer that keeps the focus on the listview. It has a search function, but it always gives the focus back to the listview. So I do not need the hidden default button. Hope this helps. _________________ "Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data... |
|
| Back to top |
|
 |
wakewatcher
Joined: 15 Jul 2006 Posts: 253
|
Posted: Sun Apr 03, 2011 7:43 am Post subject: |
|
|
Hmmm. I can trap double clicks but can't seem to trap anything else. Here's the my test case. (Running on windows 7) What am I forgetting to do?
| Code: | Gui, Add, ListView, gMyListView, Thing 1|Thing 2|Thing 3
Gui,show
LV_Add("",1,2,3)
LV_Add("",4,5,6)
LV_Add("",7,8,9)
return
MyListView:
if A_GuiEvent = DoubleClick
msgbox Double Click
else if (a_guievent = "K" && (a_eventinfo = 33 || a_eventinfo = 34 || a_eventinfo = 35 || a_eventinfo = 36 || a_eventinfo = 38 || a_eventinfo = 40)) OR (A_GuiEvent = "Normal")
Msgbox Other Stuff
Return |
|
|
| Back to top |
|
 |
flyingDman
Joined: 27 Feb 2009 Posts: 690 Location: Burbank, California
|
Posted: Sun Apr 03, 2011 7:55 am Post subject: |
|
|
Try: | Code: | | Gui, Add, ListView, gMyListView altsubmit, Thing 1|Thing 2|Thing 3 |
_________________ "Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data... |
|
| Back to top |
|
 |
wakewatcher
Joined: 15 Jul 2006 Posts: 253
|
Posted: Sun Apr 03, 2011 10:29 am Post subject: |
|
|
| Thanks. This (sorta) works. I'm getting what seems to be a bunch of spurious calls to the handler that I'm trying to figure out but this helps. |
|
| Back to top |
|
 |
flyingDman
Joined: 27 Feb 2009 Posts: 690 Location: Burbank, California
|
Posted: Sun Apr 03, 2011 3:33 pm Post subject: |
|
|
It shouldn't sorta work... It should work without a hitch. In your example, because of the msgbox action, the first click of the double click triggers the single click message box, but with the other actions this should not be a problem. _________________ "Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data... |
|
| Back to top |
|
 |
wakewatcher
Joined: 15 Jul 2006 Posts: 253
|
Posted: Sun Apr 03, 2011 4:49 pm Post subject: |
|
|
| Maybe that's it. Seems when the Gui is created/shown it gets called. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|