Key modifiers in on_gui_click

Things that already exist in the current mod API
Post Reply
User avatar
apriori
Filter Inserter
Filter Inserter
Posts: 255
Joined: Thu Feb 18, 2016 8:13 pm
Contact:

Key modifiers in on_gui_click

Post by apriori »

It would be great if we could know which mouse button and key modifier were pressed in on_gui_click:
example
Any code or mods posted by me are WTFPL, unless otherwise copyrights are specified.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Key modifiers in on_gui_click

Post 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"
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

User avatar
apriori
Filter Inserter
Filter Inserter
Posts: 255
Joined: Thu Feb 18, 2016 8:13 pm
Contact:

Re: Key modifiers in on_gui_click

Post 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"
  }
})
Any code or mods posted by me are WTFPL, unless otherwise copyrights are specified.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Key modifiers in on_gui_click

Post by aubergine18 »

yes, you are correct
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7346
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Key modifiers in on_gui_click

Post 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)
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

kiba
Filter Inserter
Filter Inserter
Posts: 344
Joined: Thu Jun 11, 2015 5:32 am
Contact:

Re: Key modifiers in on_gui_click

Post 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.

mknejp
Fast Inserter
Fast Inserter
Posts: 154
Joined: Wed Apr 27, 2016 8:29 pm
Contact:

Re: Key modifiers in on_gui_click

Post 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
 ...

Supercheese
Filter Inserter
Filter Inserter
Posts: 841
Joined: Mon Sep 14, 2015 7:40 am
Contact:

Re: Key modifiers in on_gui_click

Post 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

User avatar
Mooncat
Smart Inserter
Smart Inserter
Posts: 1184
Joined: Wed May 18, 2016 4:55 pm
Contact:

Re: Key modifiers in on_gui_click

Post by Mooncat »

I second this. And I think mknejp's solution works better.
I want to play more Factorio. I want to mod more Factorio.
But life sucks. So many things I need to do. So many things I want to do. So little time.

Rseding91
Factorio Staff
Factorio Staff
Posts: 12231
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Key modifiers in on_gui_click

Post 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.
If you want to get ahold of me I'm almost always on Discord.

credomane
Filter Inserter
Filter Inserter
Posts: 271
Joined: Tue Apr 12, 2016 6:21 pm
Contact:

Re: Key modifiers in on_gui_click

Post 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).

Rseding91
Factorio Staff
Factorio Staff
Posts: 12231
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Key modifiers in on_gui_click

Post 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.
If you want to get ahold of me I'm almost always on Discord.

credomane
Filter Inserter
Filter Inserter
Posts: 271
Joined: Tue Apr 12, 2016 6:21 pm
Contact:

Re: Key modifiers in on_gui_click

Post 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.

User avatar
apriori
Filter Inserter
Filter Inserter
Posts: 255
Joined: Thu Feb 18, 2016 8:13 pm
Contact:

Re: Key modifiers in on_gui_click

Post 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.
Any code or mods posted by me are WTFPL, unless otherwise copyrights are specified.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7346
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Key modifiers in on_gui_click

Post by bobingabout »

Well, I wanted somethng crazy like "L", but, I could work with the standard 3 key modifiers.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Key modifiers in on_gui_click

Post 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.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

credomane
Filter Inserter
Filter Inserter
Posts: 271
Joined: Tue Apr 12, 2016 6:21 pm
Contact:

Re: Key modifiers in on_gui_click

Post 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

Post Reply

Return to “Already exists”