onClick does not respond to ctrl-click How can I c...
# compose-desktop
s
onClick does not respond to ctrl-click How can I change that? On a higher level I use the onKeyEvent to mark if the user is holding down ctrl or shift and I want the onClick() to respond differently when the modifier is pressed down I don't see another option to know the modifier since the combinedClickable/clickable lambda does not provide access to these modifiers.
i
Does
onClick(keyboardModifiers =
work?
Copy code
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.onClick
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.isCtrlPressed
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.singleWindowApplication

@OptIn(ExperimentalFoundationApi::class)
fun main() = singleWindowApplication {
    Box(Modifier
        .size(200.dp)
        .background(Color.Red)
        .onClick(keyboardModifiers = { isCtrlPressed }) {
            println("click")
        }
    ) {

    }
}
s
Yes, that works. With and without the modifier. But clickable does not.
Copy code
Box(
    Modifier
    .size(200.dp)
    .background(androidx.compose.ui.graphics.Color.Red)
    .clickable {
        println("clickable")
    }
) {

}
onClick() is not available in commonMain shared code