Je voulais:
-Tout controller a la manette,
-Virer joy2key pour pas qu'il soit toujours actif (ca gene pour les jeux steam, etc)
-Faire des actions perso pour fermer certains jeux,
-Pouvoir switcher entre hyperspin, Kodi (xbmc) et Steam de n'importe ou,
-Pouvoir mettre en veille/eteindre le pc de n'importe ou,
-Pouvoir lancer des commandes / miniscripts perso facilement.
Du coup, je me suis fait un script et vous détaille le fonctionnement si ca peut donner des idées ou aider certains:
Le script check toutes les 2 secondes si HyperSpin est actif, si oui, il lance Joy2Key; si non, il l'arrete.
Et donc forcement un menu, qui s'active a la pression du stick droit, il permet de
- configurer des actions AHK custom activables de n'importe ou
- switcher entre Kodi, HyperSpin, et Steam
- quitter un jeu, meme si on ne peut pas le quitter avec ESC
- shutdown / sleep le pc
- faire n'importe quoi d'autre en AHK qui est activé directement par le menu
Ce qui est pratique c'est que du coup on peut configurer tout et n'importe quoi dans Joy2Key pour HyperSpin (navigation au stick, bouton pour menu "Genres", etc)
ca ressemble a ca (oui c'est moche. mais ca fonctionne.):
J'ai fait une video du machin en qualitée pourrie:
[video][/video]
Voila; la source dessous, toute bien commentée pour le plaisir de lecture
(source en couleur en pleine page: http://pastebin.com/ucy3NfaW)
Code : Tout sélectionner
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force ; Force only one instance of script
#Persistent ; Ensure the script is permanently running
; CONFIGURATION ==================================================
; the choices available in the menu, separated with '|'
listdata := "Quit Game|HyperSpin|Steam|Kodi|Sleep|Shutdown"
; total elements in menu
elements = 6
; period for checking hyperspin running, in ms
joyrate_check = 2000
; CUSTOM SCRIPTS =================================================
; These functions are executed when a menu item is chosen
; Function is automagically called from the menu item name
; Exemple: if the menu name is "Quit Game",
; the function FQuit_Game() will be called
; function is prefixed with 'F', spaces are replaced with '_'
FQuit_Game() {
; We check for a special close event required
if WinExist("ahk_class PhyreFrameworkClass") {
Process Close, HotlineGL.exe
} else if WinExist("ahk_class YYGameMakerYY") {
Process Close, Savant_Ascent.exe
; Else we simply send the Escape key
} else {
Send {Escape}
}
}
FHyperSpin() {
Process Close, Kodi.exe
Run, "steam://ExitSteam"
if WinExist("ahk_class ThunderRT6FormDC") ; dafuq HyperSpin
WinActivate
else
Run, "D:\HeavyBox\HyperSpin.exe"
}
FSteam() {
Process Close, HyperSpin.exe
Process Close, Kodi.exe
FQuit_Game()
Process Exist, Steam.exe
if ErrorLevel
Run, "steam://open/bigpicture"
else
Run, "C:\Program Files (x86)\Steam\Steam.exe" -bigpicture
}
FKodi() {
Process Close, HyperSpin.exe
Run, "steam://ExitSteam"
FQuit_Game()
if WinExist("ahk_class Kodi")
WinRestore
else
Run, "D:\Kodi\Kodi.exe"
}
FSleep() {
; Sleep/Suspend:
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
; Hibernate:
; DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
}
FShutdown() {
Shutdown, 1
}
; ================================================================
index = 1
active := false
prevj2kstatus := false
; Run Joy2Key timer check (that executes label 'CustomJoy2Key' regularly)
setTimer, CustomJoy2Key, %joyrate_check%
; Gui menu settings
Gui +LastFound +AlwaysOnTop +ToolWindow -Caption
Gui, color, 000000
Gui, font, s18 bold, Arial
Gui, Add, Listbox, h192 vActionmenu Choose%index%, %listdata%
; Shows or hide menu
Toggle_GUI() {
global active
if (active=true) {
active := false
Gui, Cancel
} else {
active := true
Gui, Show ;, NoActivate ; this avoid activating ahk window
}
}
; Navigation in menu when menu active
ChoiceMove(dir) {
global index, elements
elemv = elements - 1
if (index > 0 and index < elements and dir = "down")
index++
else if (index > 1 and index < elemv and dir = "up")
index--
GuiControl, Choose, Actionmenu, %index%
}
; Action on menu selection
ChoiceValidate() {
global Actionmenu, active
Gui, Submit
active := false
StringReplace, Actionmenu, Actionmenu, %A_SPACE%, _, All
; Run the function named F[menu_entry]
F%Actionmenu%()
}
; xb360 RHat shows/hide menu
1joy10::Toggle_GUI()
; navigation hotkeys only when menu active
#IfWinActive ahk_class AutoHotkeyGUI
1joy1::ChoiceValidate()
1joy3::ChoiceMove("down")
1joy4::ChoiceMove("up")
return
; The 'function' that checks regularly if HyperSpin is active
; If yes it runs Joy2Key, else it kills it
CustomJoy2Key:
if WinActive("ahk_class ThunderRT6FormDC") {
if (prevj2kstatus=false) {
Run, D:\HeavyBox\Joy2key\JoyToKey.exe
prevj2kstatus := true
}
} else {
if (prevj2kstatus=true) {
Process Close, JoyToKey.exe
prevj2kstatus := false
}
}
return