Using external devices as inputs for data entry

Hi QField community :slight_smile:

I am investigating methods of entering data without interacting with the mobile device’s screen, and I wonder if anyone had experience of this? I already use the volume buttons for data entry, but it won’t work for my use case.

My use case is recording bird flight height data. The surveyors need to keep their eyes on the bird in flight (with binoculars), otherwise they risk losing it and, therefore, data. For tracking time, we use an interval timer attached to the binoculars that can be started/stopped easily with one finger (e.g. while wearing gloves). This works well for recording the flight duration and number of 15-second intervals in the flight, but not the amount of intervals (time) that the bird flew at each height band. The surveyor usually relies on memory to record height data at the end of the flight (after drawing the flight path), by counting the number of intervals where the bird was flying at various height bands. This is expecially challanging to obtain an accurate count for long flights.

If we could easily record either the elapsed time in each height band, or the number of intervals at each height band, then:

  • the workflow would be much more efficient, as the time consuming aspect of recording the flight in QField is entering height data; and
  • the data would be more accurate, as it doesn’t depend on the surveyors memory.

I’m thinking, therefore, that a device with a button for each height band could be used like a mutually exclusive bank of timers, perhaps in combination with a QML widget that also provides large touchscreen buttons for each height band.

So, my question is: would it be possible to use a bluetooth keypad/controller/etc and map buttons to certain functions in the QField interface (or inside a QML widget).

For example, the workflow might be:

  1. the surveyor has a form for the ‘timer’ layer open, ready for the next target bird to flight through the survey area.
  2. upon spotting the bird, they press the button corresponding with the height band that the bird is flight within. A timer begins.
  3. when the bird changes height band, the surveyor presses the relevant height band button, which records an height change event associated with that height band.
  4. this continues until the end of the flight, when the surveyor presses the ‘stop’ button.
  5. total flight duration and total duration within each height band are displayed for the user to enter after recording the flight line.

Cheers,

hello @StormPetryl !

Very interesting challenge you got there! I think a good start could be the following:

  • For the big quick buttons to input things on the screen, you can check the Quick Capture Plugin made by user @coastalrocket.
  • For the physical buttons, the simplest approach I can think of is to use some gaming controller that has a software that allows you to map buttons to areas of the screen. Some ‘gaming’ branded phones and tablets also come with this function built-in for generic controllers. Some of this controllers are bluetooth, some pretty small and some wrap around the phone or tablet, so they should allow you a lot of flexibility with mounting options.
  • For the times of the height bands, an approach could be to store each change of band as a feature and use Default Expressions to populate each feature’s attributes. One attribute could be the “absolute time” at which each event occurred, maybe simply storing the value of the now() function. This should give you a good backup/starting point to get the time intervals; for that you can create another attribute/column that uses the age() function to get the delta between the “absolute time” of this feature and some other, maybe the previous one or one that could be identified as the starting/beginning one.

Thanks @cuprico, that’s really helpful. The screen area mapping approach may well provide a practical solution, and I’ll have a look at the Quick Capture Plugin too. I may well end up write my own plugin for this workflow.

I’m also wondering whether I could bypass screen-position mapping entirely and handle the Bluetooth controller as a keyboard/HID.

I’ve read that QField can already use Bluetooth keyboards and mice for interactions like clicking and typing text, and of course QField has the built-in option for using the device volume keys while digitising. Some small Bluetooth controllers I’ve found can present themselves to Android as keyboards and send keys such as Up/Down arrows, Page Up/Page Down, Enter, Space, volume/media keys, etc. There are options like wearable rings (or foot pedals) that could be potentially be operated while looking through binoculars.

In summary, what I’m trying to establish is: Can a QField QML/JavaScript plugin receive and act on arbitrary HID keyboard events, preferably regardless of UI focus?

In some more detail:

1. Does QField natively recognise any keyboard keys as commands/shortcuts outside normal text entry?

For example, do Tab, arrow keys, Page Up/Down, Enter, Escape, function keys, etc. have defined navigation/actions in QField? If so, is there a list of supported keyboard shortcuts anywhere?

2. More importantly, can a custom QField QML/JavaScript plugin listen for keyboard/key events and map them to arbitrary plugin actions?

For example, I’d ideally like to hard-code something along the lines of:

‘Page Up’ → height band UP

‘Page Down’ → height band DOWN

‘Space’ → undo last height change

Enter → stop timer

The controller wouldn’t need to know anything about QField. It would simply send those keyboard events over Bluetooth, and the plugin would decide what they mean.

3. If that is possible, does the plugin/widget need keyboard focus to receive the event, or can a plugin register a shortcut/key handler that remains active while I’m elsewhere in the QField interface?

This is important for my use case because the observer will be looking through binoculars rather than interacting visually with the tablet. So, if they can remotely control QField with some buttons attached to their binoculars, they do not need to look at the tablet and risk losing the bird. We could make it work with a more rigid field protocol if focus is essential.

4. Can key press and key release/hold events be distinguished?

If so, a two-button foot pedal might potentially support:

left short press → height down

right short press → height up

left long press → undo

right long press → stop

My ideal solution would be a small Bluetooth HID controller whose buttons send ordinary keyboard events, with the QField plugin mapping those events to my survey functions. That seems potentially more robust (and aligned with my goal to minimise touchscreen interaction during this specific survey type) than mapping controller buttons to fixed touchscreen coordinates.

Is that currently possible with the QField plugin API, or would it need a change/feature request in QField?

I’m happy to buy a couple of cheap Bluetooth controllers/pedals and test what Android/QField actually receives if that would help.

Cheers,

Yeah, having the capability of mapping HID events to complex (or even simple!) actions on QField would be awesome! No idea if it can be done purely on the QML side, maybe others on the forum would know more.

Maybe some other protocols worth exploring could be MIDI and things like that. I’d imagine things as widespread and non-essential like those might be more easily accessible, from the “OS security” side of things.

One possible issue I imagine is that keyboards, specially on mobile OSs like android, tend to have very restrictive and intrusive mappings that some times can’t be disabled; so things that work fine on a desktop environment (where one would typically develop a plugin) might have unexpected side-effects on mobile. Although I’ve seen that happen primarily with non-alphanumeric keys and key-combinations.

Another thing is that I don’t imagine a keyboard API to handle “analogue” values very well, but by what you say it’s probably not a use-case you might care or need. Just wanted to mention it since I think those two might be the biggest limitations with a “keyboard” approach.

I’m quite confident it’s possible… While reading, I was thinking of Flipper Zero device that may do that…
When I have time, I will try !

Heya!

You can add shortcuts to plugins like this utilizing Qt QML’s Shortcut class

import QtQuick

Item {
    parent: iface.mainWindow().contentItem
    property var mainWindow: iface.mainWindow()

    Shortcut {
        sequence: "Alt+F"
        context: Qt.WindowShortcut
        autoRepeat: false
        enabled: true
        onActivated: mainWindow.displayToast(qsTr('Shortcut pressed!'))
    }
}

Just tried this as an example plugin on PC, but I can’t test it on mobile since I don’t have a wireless keyboard. Should work the same nonetheless.