VirtualKey for Gamepad/Joystick input
Moderators: JRL, Dorian (MJT support)
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
VirtualKey for Gamepad/Joystick input
I'm trying to make an "extra" keyboard for our workshop users so that they can make inputs using their feet. For this I plan to use a gamepad DIY module (usually made to build arcade machines). I just need to find a way to use the input from joystick.
https://learn.microsoft.com/en-us/uwp/a ... inrt-22621
https://learn.microsoft.com/en-us/windo ... _keystroke
https://learn.microsoft.com/en-us/windo ... -key-codes
Looking at these links it looks like it similar to how the mouse and keyboard is using virtual keys. It's possible to address individual joysticks/gamepads but I'm only interested in any joystick's/gamepad's button being clicked.
Will MS allow for gamepad input for the OnEvent?
It's a good complement for the use of keyboard input because it would not ever be a conflict with other app's keyboard commands.
https://learn.microsoft.com/en-us/uwp/a ... inrt-22621
https://learn.microsoft.com/en-us/windo ... _keystroke
https://learn.microsoft.com/en-us/windo ... -key-codes
Looking at these links it looks like it similar to how the mouse and keyboard is using virtual keys. It's possible to address individual joysticks/gamepads but I'm only interested in any joystick's/gamepad's button being clicked.
Will MS allow for gamepad input for the OnEvent?
It's a good complement for the use of keyboard input because it would not ever be a conflict with other app's keyboard commands.
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: VirtualKey for Gamepad/Joystick input
If we look in the help: https://help.mjtnet.com/article/262-virtual-key-codes we see that these VK codes are reserved:
195 GamepadA
196 GamepadB
197 GamepadX
198 GamepadY
199 GamepadRightShoulder
200 GamepadLeftShoulder
201 GamepadLeftTrigger
202 GamepadRightTrigger
203 GamepadDPadUp
204 GamepadDPadDown
205 GamepadDPadLeft
206 GamepadDPadRight
207 GamepadMenu
208 GamepadView
209 GamepadLeftThumbstickButton
210 GamepadRightThumbstickButton
211 GamepadLeftThumbstickUp
212 GamepadLeftThumbstickDown
213 GamepadLeftThumbstickRight
214 GamepadLeftThumbstickLeft
215 GamepadRightThumbstickUp
216 GamepadRightThumbstickDown
217 GamepadRightThumbstickRight
218 GamepadRightThumbstickLeft
But in this link they are Gamepad VK's. https://learn.microsoft.com/en-us/uwp/a ... inrt-22621
195 GamepadA
196 GamepadB
197 GamepadX
198 GamepadY
199 GamepadRightShoulder
200 GamepadLeftShoulder
201 GamepadLeftTrigger
202 GamepadRightTrigger
203 GamepadDPadUp
204 GamepadDPadDown
205 GamepadDPadLeft
206 GamepadDPadRight
207 GamepadMenu
208 GamepadView
209 GamepadLeftThumbstickButton
210 GamepadRightThumbstickButton
211 GamepadLeftThumbstickUp
212 GamepadLeftThumbstickDown
213 GamepadLeftThumbstickRight
214 GamepadLeftThumbstickLeft
215 GamepadRightThumbstickUp
216 GamepadRightThumbstickDown
217 GamepadRightThumbstickRight
218 GamepadRightThumbstickLeft
But in this link they are Gamepad VK's. https://learn.microsoft.com/en-us/uwp/a ... inrt-22621
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: VirtualKey for Gamepad/Joystick input
You can specify any virtual key code in OnEvent with KEY_DOWN, KEY_UP, by preceding the code with VK. So, yes, if these are the VK codes that your custom keyboard triggers, you should be able to respond to them with OnEvent.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: VirtualKey for Gamepad/Joystick input
I guess it wasn't that easy... this is not working:
I found some more info here: https://learn.microsoft.com/sv-se/windo ... dfrom=MSDN
Code: Select all
//button A = 195
OnEvent>KEY_DOWN,VK195,0,TEST
Label>START
Wait>1
Goto>START
SRT>TEST
MDL>195 GamepadA - pressed
Exit>
END>TEST
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: VirtualKey for Gamepad/Joystick input
Use a dialog to see what key code IS being sent.
Debug this code. Make sure the dialog is active. Hit your game pad key and see what the value of SUBTEST_KEY is:
Debug this code. Make sure the dialog is active. Hit your game pad key and see what the value of SUBTEST_KEY is:
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
Left = 607
Top = 264
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 211
ClientWidth = 476
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
KeyPreview = True
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,,OnKeyPress,subTest
Show>Dialog1,r
SRT>subTest
**BREAKPOINT**
// see what value of SUBTEST_KEY is - that is the VK code
END>subTest
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: VirtualKey for Gamepad/Joystick input
Great little code there. Thanks for that! 
But, the gamepad isn't triggering anything so I guess that the gamepad isn't acting like a normal input after all. Would you consider looking into this and see if it's possible to add this feature to MS?

But, the gamepad isn't triggering anything so I guess that the gamepad isn't acting like a normal input after all. Would you consider looking into this and see if it's possible to add this feature to MS?

- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: VirtualKey for Gamepad/Joystick input
I'm wondering if this would be considered to be added?
Re: VirtualKey for Gamepad/Joystick input
Hi Grovkillen,
Wondering if the gamepad is a serial device. Are you able to use it as input for standard windows software? For example, does it have any effect in notepad? Does it show up under Device Manager? If yes, what?
Wondering if the gamepad is a serial device. Are you able to use it as input for standard windows software? For example, does it have any effect in notepad? Does it show up under Device Manager? If yes, what?
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: VirtualKey for Gamepad/Joystick input
They are not serial as in COM, they are part of the USB standard and are identified as XInput devices. As long as a controller/gamepad/joystick comply to this standard no drivers are needed. It's been this way since the Xbox 360 got introduced.
I just happened to see that the VK enums contained the gamepad input as well and was hoping that this would mean that it worked out of the box. But, it's not...
My hope is that Macro Scheduler would find use of Xinput support since it's a great way of having input using other hardware than mouse and keyboard. XInput modules are easy to come by and thus I could make foot pedals and other breakers input to scripts without the risk of having them crash with keyboard inputs (JoyToKey.exe emulates a keyboard/mouse using a gamepad).
I just happened to see that the VK enums contained the gamepad input as well and was hoping that this would mean that it worked out of the box. But, it's not...
My hope is that Macro Scheduler would find use of Xinput support since it's a great way of having input using other hardware than mouse and keyboard. XInput modules are easy to come by and thus I could make foot pedals and other breakers input to scripts without the risk of having them crash with keyboard inputs (JoyToKey.exe emulates a keyboard/mouse using a gamepad).
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: VirtualKey for Gamepad/Joystick input
Here's some AutoHotKey discussions regarding XInput: https://www.autohotkey.com/board/topic/ ... oller-api/
- Grovkillen
- Automation Wizard
- Posts: 1132
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: VirtualKey for Gamepad/Joystick input
Maybe a Delphi library could be used? https://blogs.embarcadero.com/add-insta ... n-windows/