Page 1 of 1

Link gamepad button to keyboard key

Posted: Sun May 23, 2010 10:19 pm
by Le Soldat Inconnu
Hi,

I try to do small program to "drive" my keyboard and mouse with a gamepad. It's to can play game (Risen, if you want know) which don't accept gamepad input

There no problem with mouse, it's work fine.
But with keyboard, it's totally don't works.

When i simulate keyboard, i arrive to send #vk_KeySomething to program but it's don't do like real key pressed.

I do this example
i try to simule Right key and see if this key is pressed with ExamineKeyboard()
But i see nothing

Code: Select all

ExamineDesktops()
Ecran_Largeur = DesktopWidth(0)
Ecran_Hauteur = DesktopHeight(0)

; On ouvre l'openscreen
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0 Or InitSprite3D() = 0
  MessageRequester("Erreur", "Impossible d'initialiser la souris ,le clavier ou l'écran. Vérifiez la présence de DirectX 7 ou supérieur.", 0)
  End
EndIf

If OpenScreen(Ecran_Largeur, Ecran_Hauteur, 32, "Ecran", #PB_Screen_WaitSynchronization, DesktopFrequency(0)) = 0
  MessageRequester("Erreur", "Impossible d'ouvrir l'écran.", 0)
  End
EndIf



Repeat
  ClearScreen($000000)
	
	Message.INPUT
	Message\Type = #INPUT_KEYBOARD
	Message\ki\wVk = #VK_RIGHT
	Message\ki\dwFlags = 0
	SendInput_(1, @Message, SizeOf(INPUT))
	
  ; On lit les évènements clavier et souris
  ExamineMouse()
  ExamineKeyboard()
  
  ; Position de la souris
  x = MouseX()
  y = MouseY()
  If KeyboardPushed(#PB_Key_Right)
		FD = 1
	Else
		FD = 0
	EndIf
	
  StartDrawing(ScreenOutput())
		DrawText(10, 10, "x = " + Str(x))
		DrawText(10, 30, "y = " + Str(y))
		DrawText(10, 50, "Fleche droite, Right key = " + Str(FD))
	StopDrawing()
  
	Message\Type = #INPUT_KEYBOARD
	Message\ki\wVk = #VK_RIGHT
	Message\ki\dwFlags = #KEYEVENTF_KEYUP
	SendInput_(1, @Message, SizeOf(INPUT))
  
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape)
Thanks for your help

Re: Link gamepad button to keyboard ley

Posted: Sun May 23, 2010 11:55 pm
by Fluid Byte

Re: Link gamepad button to keyboard ley

Posted: Mon May 24, 2010 1:36 am
by J. Baker
I don't see any joystick commands. I also made a similar program some years ago with PB. http://www.flashpulse.com

Re: Link gamepad button to keyboard ley

Posted: Mon May 24, 2010 7:23 am
by Le Soldat Inconnu
JoyToKey don't works too :mrgreen: Same problem as me. I think it's because directX
I don't see any joystick commands
It's normal, my only problem, it's to catch simulate keyboard key in game. So i just simulte keyboard key and i try to catch it in game

Re: Link gamepad button to keyboard key

Posted: Mon May 24, 2010 6:34 pm
by Le Soldat Inconnu
it's ok, i find, we have to use ScanCode in SendInput_()

and code are specific, it's code from this page
http://msdn.microsoft.com/en-us/library/ms835978.aspx

just add filter &$FFFF to value of this page to transform in ScanCode.
And it's work perfectly with DirectX