I've been trying to do a multipurpose On-Screen micro keyboard, pad or gamepad, but I'm stuck at the final steps as my attempts lack the desired results.
My ideal or goal is to make the buttons behave like the buttons in the integrated Windows OSK as much as possible, but with a flexible layout that it can be from 1-3 buttons to a full gamepad. As a person with limited mobility due a motor disability this kind of projects helps me greatly.
Version A
Code: Select all
#NoEnv
#SingleInstance force
SetKeyDelay, 20, 10
SetMouseDelay, 10
SetBatchLines,-1
; Set the size of the gamepad
Width := 355
Height := 180
; Gamepad variables
global btnPressed = ""
global btnList := {ButtonA: "a", ButtonB: "b", ButtonC: "c", ButtonX: "x", ButtonY: "y", ButtonZ: "z", ButtonM: "q", ButtonN: "space", ButtonO: "e", ButtonTL: "e", ButtonTR: "r", ButtonStart: "enter", ButtonSelect: "backspace", ButtonKU: "Up", ButtonKD: "Down", ButtonKL: "Left", ButtonKR: "Right"}
; Create the GUI for the gamepad
Gui, +LastFound +AlwaysOnTop +ToolWindow +Border +E0x08000000
Gui, Color, FEFEFE +LastFound
; WinSet, TransColor, FEFEFE 220
Gui, Add, Button, x200 y60 w40 h40 gCtrlEvent vButtonA, A
Gui, Add, Button, x242 y30 w40 h40 gCtrlEvent vButtonB, B
Gui, Add, Button, x284 y60 w40 h40 gCtrlEvent vButtonC, C
Gui, Add, Button, x200 y102 w40 h40 gCtrlEvent vButtonX, X
Gui, Add, Button, x242 y72 w40 h40 gCtrlEvent vButtonY, Y
Gui, Add, Button, x284 y102 w40 h40 gCtrlEvent vButtonZ, Z
Gui, Add, Button, x72 y30 w40 h40 gCtrlEvent vButtonKU, Up
Gui, Add, Button, x30 y50 w40 h40 gCtrlEvent vButtonKL, Left
Gui, Add, Button, x114 y50 w40 h40 gCtrlEvent vButtonKR, Right
Gui, Add, Button, x72 y72 w40 h40 gCtrlEvent vButtonKD, Down
Gui, Add, Button, x30 y100 w40 h40 gCtrlEvent vButtonSelect, Select
Gui, Add, Button, x114 y100 w40 h40 gCtrlEvent vButtonStart, Start
Gui, Show, x900 y320 w%Width% h%Height%
; I can't remember for what is this for
DllCall("SetClassLong","UInt",hWnd,"Int",-26,"UInt",0x8)
; They work but I can't trigger these fast
OnMessage(0x0202, "WM_LBUTTONUP")
OnMessage(0x201, "WM_LBUTTONDOWN")
return
Esc::ExitApp
WM_LBUTTONUP(wParam, lParam, msg, hwnd) {
Send {blind}{%btnPressed% up}
}
WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {
btnVar := A_GuiControl
btnPressed := btnList["" . btnVar]
Send {blind}{%btnPressed% down}
}
; Just in case it would be needed
CtrlEvent(CtrlHwnd:=0, GuiEvent:="", EventInfo:="", ErrLvl:="") {
GuiControlGet, controlName, Name, %CtrlHwnd%
}
Version B
Code: Select all
#NoEnv
#SingleInstance force
SetKeyDelay, 20, 10
SetMouseDelay, 10
SetBatchLines,-1
; Set the size of the gamepad
Width := 440
Height := 200
; Gamepad variables
global btnPressed = ""
global btnList := {ButtonA: "z", ButtonB: "x", ButtonC: "c", ButtonX: "enter", ButtonY: "y", ButtonZ: "z", ButtonM: "q", ButtonN: "space", ButtonO: "e", ButtonTL: "e", ButtonTR: "r", ButtonStart: "enter", ButtonSelect: "backspace", ButtonKU: "Up", ButtonKD: "Down", ButtonKL: "Left", ButtonKR: "Right"}
; Create the GUI for the gamepad
Gui, +LastFound +AlwaysOnTop +ToolWindow +Border +E0x08000000
Gui, Color, FEFEFE +LastFound
; WinSet, TransColor, FEFEFE 220
Gui, Add, Text, 0x5 x10 y10 w205 h120 gCtrlEvent vButtonA cBlack, Button B
Gui, Add, Text, 0x5 x225 y10 w205 h120 gCtrlEvent vButtonB, Button A
Gui, Add, Text, 0x5 x135 y150 w80 h30 gCtrlEvent vButtonC, Select
Gui, Add, Text, 0x5 x225 y150 w80 h30 gCtrlEvent vButtonX, Start
Gui, Show, x1300 y400 w%Width% h%Height%
; I can't remember for what is this for
DllCall("SetClassLong","UInt",hWnd,"Int",-26,"UInt",0x8)
; They work but I can't trigger these fast
OnMessage(0x0202, "WM_LBUTTONUP")
OnMessage(0x201, "WM_LBUTTONDOWN")
return
Esc::ExitApp
; WM_LBUTTONUP(wParam, lParam, msg, hwnd) {
; Send {blind}{%btnPressed% up}
; }
WM_LBUTTONDOWN(wParam, lParam, msg, hwnd) {
btnVar := A_GuiControl
btnPressed := btnList["" . btnVar]
Send {blind}{%btnPressed% down}
KeyWait, LButton
Send {blind}{%btnPressed% up}
}
; Just in case it would be needed
CtrlEvent(CtrlHwnd:=0, GuiEvent:="", EventInfo:="", ErrLvl:="") {
GuiControlGet, controlName, Name, %CtrlHwnd%
}
Thanks in advance!