Author Topic: Key management question  (Read 306 times)

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1772
Key management question
« on: March 27, 2019, 08:43:33 PM »
@a1ex

Hope you can quickly help and put me out of my misery.

‘All’ I’m trying to do is use event.keypress to look out only (sic) for a half shutter press and not a full shutter press.

My question is, when you do a full shutter press, does the key event handler go through the full sequence, ie halfshuuter, fullshuuter, fullshutterunpress, halfshutterunpress, or some other logic.

Thus if I look for and halfshutterunpress and a key.last == fullshutterunpress I should be ok. But when I try this, it doesn’t seem to work.

Cheers

Garry

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1772
Re: Key management question
« Reply #1 on: March 27, 2019, 10:11:44 PM »
@a1ex

Worked it out, but don't understand the problem.

It seems key.last doesn't work inside event.keypress.

Thus, if I use this code, it doesn't work:

Code: [Select]
    if (kk == KEY.UNPRESS_HALFSHUTTER) and key.last ~= 4 then -- reset and change direction of ML state changes
        direction = -direction
        return true
    end

But if I use this code and explicitly track the last key, ie the last variable, myself, then all is well:

Code: [Select]
    if (kk == KEY.UNPRESS_HALFSHUTTER) and last ~= 4 then -- reset and change direction of ML state changes
        direction = -direction
        return true
    end

garry23

  • Contributor
  • Hero Member
  • *****
  • Posts: 1772
Re: Key management question
« Reply #2 on: March 27, 2019, 10:43:23 PM »
Even simpler :-)

Code: [Select]
    if (kk == KEY.UNPRESS_HALFSHUTTER) and last_key == KEY.HALFSHUTTER  then -- reset and change direction of ML state changes
        direction = -direction
        last_key = kk
        return true
    end

Thinking about it, I guess key.last hasn't been set until the key event completes. So I’ll just explicitly track myself :-)