Link gamepad button to keyboard key

Just starting out? Need help? Post your questions and find answers here.
User avatar
Le Soldat Inconnu
Enthusiast
Enthusiast
Posts: 306
Joined: Wed Jul 09, 2003 11:33 am
Location: France

Link gamepad button to keyboard key

Post 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
Last edited by Le Soldat Inconnu on Mon May 24, 2010 7:59 am, edited 1 time in total.
LSI
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Link gamepad button to keyboard ley

Post by Fluid Byte »

Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
J. Baker
Addict
Addict
Posts: 2196
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: Link gamepad button to keyboard ley

Post 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
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef


Even the vine knows it surroundings but the man with eyes does not.
User avatar
Le Soldat Inconnu
Enthusiast
Enthusiast
Posts: 306
Joined: Wed Jul 09, 2003 11:33 am
Location: France

Re: Link gamepad button to keyboard ley

Post 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
LSI
User avatar
Le Soldat Inconnu
Enthusiast
Enthusiast
Posts: 306
Joined: Wed Jul 09, 2003 11:33 am
Location: France

Re: Link gamepad button to keyboard key

Post 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
LSI
Post Reply