Author Topic: Device Input Question  (Read 5433 times)

0 Members and 1 Guest are viewing this topic.

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Device Input Question
« on: December 01, 2021, 12:30:39 pm »
Hi QB64 community.  First off, let me just say a big thank you to all who are keeping this project going.  I have had an absolute blast since I found this project.  Like many others I was trying to find a way to run my old QBasic projects on a modern OS without needing a virtual DOS machine.  I've been impressed with the modern extensions especially as regards to the graphics capabilities which are available.

So I've been working on some new game-related material that I hope to share shortly and I've run into what seems like a cross-platform compatibility issue with device input.  I'm trying to use a flexible device input scheme that would allow dynamic mapping of inputs to game actions, regardless of whether the input is from a keyboard, mouse or game controller.

On windows the idea is working as expected.  However, when I try to run the code on Linux or MacOS it does not seem as though the keyboard events are being caught by the device import methods.

Here is a bit of sample code to demonstrate:
Code: QB64: [Select]
  1.     Dim i As Integer
  2.     For i = 1 To _Devices
  3.         If _DeviceInput(i) Then
  4.             Cls
  5.             Locate 1, 1
  6.             Print Str$(i) + " : " + _Device$(i) + " : " + Str$(_LastButton(i))
  7.             Dim j As Integer
  8.             For j = 1 To _LastButton(i)
  9.                 If _Button(j) Then
  10.                     Print "button: " + Str$(j)
  11.                 End If
  12.             Next j
  13.         End If
  14.     Next i
  15.     _Limit 60
  16.  

If you run this on windows you will see button ids corresponding to the keys that are pressed down.  However, on Linux and MacOS it only seems to be detecting mouse and controller button events.

If this has already been addressed in another thread or there is an open issue that I missed just let me know and forgive my noobness.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Device Input Question
« Reply #1 on: December 01, 2021, 12:51:00 pm »
Welcome @dbox

Wow I didn't even know you could access Keyboard with Device keywords. Well SMcNeill has done some work with devices but don't know if he knows much about Linux.

What you are after seems like it would be very useful. :)

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
    • View Profile
Re: Device Input Question
« Reply #2 on: December 03, 2021, 12:50:26 am »
Wow I didn't even know you could access Keyboard with Device keywords. Well SMcNeill has done some work with devices but don't know if he knows much about Linux.

What you are after seems like it would be very useful. :)

Definitely - I would be interested in hearing how this gets resolved. I've been planning on adding a dynamic keyboard and game controller mapping utility to my games, and would want it to be cross platform. 

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Device Input Question
« Reply #3 on: December 03, 2021, 01:42:35 am »
I know it *used* to work on Linux and Mac, but I have no idea if it still does.  I don't have a Linux machine up and going at the moment for testing.   One thing I do know is that _DEVICES fails to recognize all your key presses and gives false results in certain cases, particularly in regard to combination-keys (Alt-Tab, Ctrl-I, and such).  Be careful to check to make certain such combinations are possible, before you try to assign them to something in your project.  Also check for duplicates such as CTRL-H returning the same code as Delete, for example.

Various keys are unmapped.  Other various keys are mismapped.  And other keys are duplicate mapped....  And, from my memory, Linux and Windows and Mac each have their own unique set of combo-keys which give false results.  (CTRL-H might report a value of 8 in Windows, a value of 34568 in Linux, for example.)

As long as you're sticking with single keypress results, _DEVICES works passably well.  (Except for the keys it fails to register completely.)  If you need combo-keys however, you'll want to thoroughly  test them before assigning them into your project.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Device Input Question
« Reply #4 on: December 03, 2021, 01:47:32 am »
Definitely - I would be interested in hearing how this gets resolved.

On this part, I wouldn't hold my breath.  I've been hoping for a complete input overhaul for all our input commands (they're all buggy in various, different manners) for the last five years.  It hasn't happened yet, and I don't expect it to happen in the next fifty year either.  Not enough people use QB64 for anything more than just small, basic little programs and there's no outstanding cry for better/more reliable input out there.  Fixing it isn't even on the list of priorities.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Device Input Question
« Reply #5 on: December 03, 2021, 03:13:05 am »
Can you guys tell me if this works at all in your non-Windows systems (try it on Windows too, it's a fun little game): https://github.com/FellippeHeitor/Spaceship

I have it working properly for me on both Windows and macOS - don't recall testing it on Linux though.

At start, the game will ask you if you want keyboard or joystick input (if any is found). Then it lets you customize what keys/buttons you want to use for directions, shooting, etc.

If it does work for you, as it does for me, please feel free to adapt my input routines for your needs. I'm using _DEVICES et al.

FellippeHeitor

  • Guest
Re: Device Input Question
« Reply #6 on: December 03, 2021, 03:26:08 am »
Oh, nevermind. I just revisited my own code and I am using _KEYHIT for keyboard input, likely due to the listed issues.

The code is cool for controllers anyway.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Device Input Question
« Reply #7 on: December 03, 2021, 06:16:27 am »
Runs on my Linux box... Runs a little too well... lol Killed off several times... *sigh*
Logic is the beginning of wisdom.

Offline dbox

  • Newbie
  • Posts: 80
    • View Profile
Re: Device Input Question
« Reply #8 on: December 03, 2021, 07:56:49 am »
Thank you all for the feedback.  @SMcNeill, I can tell this is a sensitive subject for you.  Overall the device input functionality has been working well for me so far with mouse and game controller input.  It also seems to detect keyboard input well on Windows.  The only missing mapping I noticed was Alt, F10 and the Print Screen key. 

Based on the feedback I'm going to just proceed for now with a workaround that will use _KeyDown for keyboard state detection.

@FellippeHeitor, your spaceship game ran just fine on my virtual linux box.  Anyone else using VMware workstation player for testing cross-platform functionality?  (https://www.vmware.com/products/workstation-player/workstation-player-evaluation.html)  Just need to download a virtual machine image.  There are a bunch of linux images here: https://www.osboxes.org/vmware-images/
« Last Edit: December 03, 2021, 08:03:20 am by dbox »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Device Input Question
« Reply #9 on: December 03, 2021, 07:57:33 am »
Can you guys tell me if this works at all in your non-Windows systems (try it on Windows too, it's a fun little game): https://github.com/FellippeHeitor/Spaceship

Runs great for me, on Zorin OS 16 Core (Linux).  Nice game!

- Dav

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Device Input Question
« Reply #10 on: December 05, 2021, 12:34:38 pm »
@SMcNeill
Do you think that is an issue about a matrix to fix into CPP side or what other thing  the base of these inaccurancy?

@FellippeHeitor
Great game I remember it started for demonstrating joystick input and it began a fine ASCII game.

I run it both on windows 7, windows 10 and Lubuntu in WM. All ok.
Programming isn't difficult, only it's  consuming time and coffee