Closed joe-chelladurai closed 3 years ago
Hey @meshach-joe thanks for providing the link to the plugin. I've made a branch that might be what you're looking for. I'll need to test it out a bit more before I merge it to master and submit to CRAN. For the time being, you can give it a spin with:
# install the branch with global bind plugin
# devtools::install_github("r4fun/keys", ref = "global-bind")
library(shiny)
library(keys)
hotkeys <- c(
"1",
"command+shift+k",
"up up down down left right left right b a enter"
)
ui <- fluidPage(
useKeys(),
keysInput("keys", hotkeys, global = TRUE),
textInput("txt", "txt input")
)
server <- function(input, output, session) {
observeEvent(input$keys, {
print(input$keys)
})
}
shinyApp(ui, server)
Note that setting global = TRUE
is only available in the keysInput
function. So I haven't written anything to allow global key bindings with something like addKeys
. Still thinking about how it should work.
Awesome! This works very well and thanks for the very quick response.
This may be a related issue, so when I tried it with shinyAce::aceEditor
, it didn't work:
library(shiny)
library(keys)
hotkeys <- c(
"1",
"ctrl+shift+k",
"up up down down left right left right b a enter"
)
ui <- fluidPage(
useKeys(),
keysInput("keys", hotkeys, global = TRUE),
textInput("txt1", "txt input"),
aceEditor("txt", "txt input",
height = "50px")
)
server <- function(input, output, session) {
observeEvent(input$keys, {
print(input$keys)
})
}
shinyApp(ui, server)
Happy to hear the textInput
is working! The shinyAce
example you provided is also working on my end. Could you clarify what the issue is?
I just found that it was an error on my end. So sorry! It works with shinyAce
Thanks for this wonderful package!
No worries! I'll keep this issue open until I merge the global-bind
branch to master.
Hi! I was wondering whether you have any update on the global-bind
branch. I'm depending on it for a personal package (works like charm, thanks) and was considering submitting to CRAN at some time.
Thanks, Valerio.
@vgherard I have admittedly forgot to merge this to master. Let me re-review my work, merge to master and get this on CRAN. I'll update this thread on any status updates. Neat package by the way!
Okay, this feature is on its way to CRAN in keys v0.1.1
!
Great, thank you so much!
Okay, this feature is on its way to CRAN in
keys v0.1.1
!
I've been trying to use shortcut keys while the cursor is inside the text input, but it doesn't work. It does work once I'm outside the textbox. Is there a way to fix this issue?
I found this to be a helpful resource to figure out a solution. I wish I knew more javascript to contribute. https://github.com/ccampbell/mousetrap/tree/master/plugins/global-bind