Page 1 of 1

Key modifiers in on_gui_click

Posted: Sun Aug 28, 2016 6:17 am
by apriori
It would be great if we could know which mouse button and key modifier were pressed in on_gui_click:
example

Re: Key modifiers in on_gui_click

Posted: Sun Aug 28, 2016 6:40 am
by aubergine18
+1

Only tweak I'd make is for consistency with way mods define keyboard shortcuts: capitalise first letter, eg. "Shift" instead of "shift"

Re: Key modifiers in on_gui_click

Posted: Sun Aug 28, 2016 6:59 am
by apriori
aubergine18 wrote:+1

Only tweak I'd make is for consistency with way mods define keyboard shortcuts: capitalise first letter, eg. "Shift" instead of "shift"
"SHIFT" - as when defining hotkeys. =)

Code: Select all

data:extend({
  {
    type = "custom-input",
    name = "my-mod-hot-key",
    key_sequence = "SHIFT + Y",
    consuming = "script-only"
  }
})

Re: Key modifiers in on_gui_click

Posted: Sun Aug 28, 2016 7:32 am
by aubergine18
yes, you are correct

Re: Key modifiers in on_gui_click

Posted: Tue Aug 30, 2016 8:07 am
by bobingabout
The ability to scan the keyboard in scripts to determine if a key is pressed or not would definitely be useful (even outside of on_gui_click), I can't remember what it was right now, but I remember I wanted to program something in where if you did something while holding a key, it would do it differently (I think it was a settings copy script if you placed an entity while holding a key)

Re: Key modifiers in on_gui_click

Posted: Thu Sep 01, 2016 9:14 pm
by kiba
apriori wrote:
aubergine18 wrote:+1

Only tweak I'd make is for consistency with way mods define keyboard shortcuts: capitalise first letter, eg. "Shift" instead of "shift"
"SHIFT" - as when defining hotkeys. =)

Code: Select all

data:extend({
  {
    type = "custom-input",
    name = "my-mod-hot-key",
    key_sequence = "SHIFT + Y",
    consuming = "script-only"
  }
})
What does "consuming" means? I can't find hotkey definitions anywhere in the lua-api doc.

Re: Key modifiers in on_gui_click

Posted: Thu Sep 01, 2016 10:01 pm
by mknejp
Instead of having key_modifier be a single value make it a dictionary to support combinations

Code: Select all

if(event.key_modifiers.SHIFT and event.key_modifiers.ALT) then
 ...

Re: Key modifiers in on_gui_click

Posted: Thu Sep 01, 2016 10:09 pm
by Supercheese
kiba wrote:What does "consuming" means? I can't find hotkey definitions anywhere in the lua-api doc.
See: http://pastebin.com/raw/k44Ed5Gz

Re: Key modifiers in on_gui_click

Posted: Fri Sep 02, 2016 4:37 am
by Mooncat
I second this. And I think mknejp's solution works better.

Re: Key modifiers in on_gui_click

Posted: Fri Sep 02, 2016 7:30 pm
by Rseding91
The current system for detecting input actions and firing events in Factorio doesn't preserve data like this.

When the button is clicked it sends a 4 byte event "button clicked" - none of the data about which button or what keys are held down is stored in that event. It works this way because those events are saved in replays and are sent over the network for Multiplayer games. If the entire keyboard state was stored in those events it would be crazy.

Because of that, this isn't likely to ever happen.

Re: Key modifiers in on_gui_click

Posted: Fri Sep 02, 2016 11:08 pm
by credomane
Would just adding another byte (really just 3 bits) to the event to keep track of modifier keys like SHIFT, CONTROL, ALT be too much?

Perhaps 1 more bit to say it was a right click otherwise assume left click (even for a middle click or mice with 4+ buttons on them).

Re: Key modifiers in on_gui_click

Posted: Fri Sep 02, 2016 11:14 pm
by Rseding91
credomane wrote:Would just adding another byte (really just 3 bits) to the event to keep track of modifier keys like SHIFT, CONTROL, ALT be too much?

Perhaps 1 more bit to say it was a right click otherwise assume left click (even for a middle click or mice with 4+ buttons on them).
If *all* you want is those modifier keys then sure I guess it wouldn't be out of the question to add those.

Re: Key modifiers in on_gui_click

Posted: Sat Sep 03, 2016 2:59 am
by credomane
Rseding91 wrote:If *all* you want is those modifier keys then sure I guess it wouldn't be out of the question to add those.
It is certainly all I want. Knowing if any modifier keys were held on click and if the click was left or right click would be absolutely amazing. :D

The only thing I could see others wanting would be to know if the SHIFT, CONTROL, and ALT modifiers were the left or right side of the keyboard.

As for all other keys on a keyboard I dunno why anyone would want the letter "K" as a modifier for a left click on a button. That even looks weird typing it out like I did.

Re: Key modifiers in on_gui_click

Posted: Sat Sep 03, 2016 9:50 am
by apriori
You are already using modifiers and mouse buttons in GUIs: in grids of inventories. I vote for the same in custom GUIs. That's all.

Re: Key modifiers in on_gui_click

Posted: Sat Sep 03, 2016 2:44 pm
by bobingabout
Well, I wanted somethng crazy like "L", but, I could work with the standard 3 key modifiers.

Re: Key modifiers in on_gui_click

Posted: Sun Sep 04, 2016 8:47 pm
by aubergine18
Just having standard key modifiers (Control, Shift, Alt) would suffice IMO. Addition of being able to determine if it was left or right mouse click would be icing on cake.

Re: Key modifiers in on_gui_click

Posted: Mon Sep 05, 2016 3:05 am
by credomane
bobingabout wrote:Well, I wanted somethng crazy like "L", but, I could work with the standard 3 key modifiers.
Of-course Bob does. Should have known. :P