[SOLVED] Disable arrow keys on imagemaps only

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

[SOLVED] Disable arrow keys on imagemaps only

#1 Post by Kinmoku »

Hi all,

I want to disable the arrow keys from rotating through hotspots in my imagemaps. Using arrow keys makes it too easy to find secret/ hidden items that I'm hoping only sharp eyes will notice!

I only want left, right, up, down disabled for the imagemaps, though. I know how to disable keymaps in general, but not for just one screen. How do I do this? Is there something I can add to the screen itself?
Last edited by Kinmoku on Mon May 20, 2019 5:20 am, edited 4 times in total.

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: Max Power and the Egyptian Beetle Case, The Candidate, The Last Hope, El cajón del viejo escritorio, Clementina y la luna roja, Caught in Orbit, Dirty Business Ep 0, Medianoche de nuevo, The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Disable arrow keys on imagemaps

#2 Post by Matalla »

Maybe running the code to disable/enable them with on "show"/"hide" statements in the imagemap screen(s)?
Comunidad Ren'Py en español (Discord)
Honest Critique

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Disable arrow keys on imagemaps

#3 Post by Alex »

Try to add this code into your imagemap screen

Code: Select all

key "focus_left" action NullAction()
key "focus_right" action NullAction()
key "focus_up" action NullAction()
key "focus_down" action NullAction()
https://www.renpy.org/doc/html/screens.html#key
https://www.renpy.org/doc/html/keymap.html#keymap
https://www.renpy.org/doc/html/screen_a ... NullAction

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Disable arrow keys on imagemaps

#4 Post by Kinmoku »

Alex wrote: Tue May 14, 2019 11:47 am Try to add this code into your imagemap screen

Code: Select all

key "focus_left" action NullAction()
key "focus_right" action NullAction()
key "focus_up" action NullAction()
key "focus_down" action NullAction()
https://www.renpy.org/doc/html/screens.html#key
https://www.renpy.org/doc/html/keymap.html#keymap
https://www.renpy.org/doc/html/screen_a ... NullAction
Ah! NullAction! I forgot.

Thanks very much, Alex :)

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: [SOLVED] Disable arrow keys on imagemaps

#5 Post by Kinmoku »

Okay, so it does what I originally asked but I have an issue... There are buttons on the screen with the imagemap which I'd like to stay selectable with the directional keys.

Here's my current code:

Code: Select all

screen shelves_imagemap:    
    imagemap:
        ground "shelves"
        hover "shelvesmap"

        hotspot (256, 407, 125, 161) clicked Return("photoframe") activate_sound "sounds/item.ogg"
        hotspot (440, 139, 276, 399) clicked Return("mirror") activate_sound "sounds/item.ogg"
        hotspot (630, 547, 272, 49) clicked Return("laptop") activate_sound "sounds/item.ogg"
        hotspot (158, 596, 746, 484) clicked Return("drawers") activate_sound "sounds/item.ogg"
        hotspot (985, 357, 192, 42) clicked Return("dvd") activate_sound "sounds/book.ogg"
        hotspot (1143, 207, 121, 150) clicked Return("bear") activate_sound "sounds/wallet.ogg"
        hotspot (943, 405, 700, 428) clicked Return("books") activate_sound "sounds/magazines.ogg"
        hotspot (1719, 482, 182, 575) clicked Return("guitar") activate_sound "sounds/item.ogg"
        hotspot (1265, 127, 142, 219) clicked Return("shirt") activate_sound "sounds/clothes.ogg"
        hotspot (952, 833, 679, 247) clicked Return("vinyl") activate_sound "sounds/item.ogg"
        hotspot (725, 484, 177, 62) clicked Return("makeup") activate_sound "sounds/item.ogg"
        
    use shelves_buttons
    use no_arrows
        
screen shelves_buttons:
    imagebutton idle "images/left1.png" hover "leftbutton" clicked Return('farmap') xpos 20 ypos 420 focus_mask True activate_sound "sounds/button.ogg"
    imagebutton idle "images/leave_button1.png" hover "leavebutton" clicked Return('leaveattempt') xanchor 0.5 xpos 0.5 ypos 910 focus_mask True activate_sound "sounds/button.ogg"
    imagebutton idle "images/right1.png" hover "rightbutton" clicked Return('nearmap') xanchor 1.0 xpos 1900 ypos 420 focus_mask True activate_sound "sounds/button.ogg"
    
screen no_arrows:
    key "focus_left" action NullAction()
    key "focus_right" action NullAction()
    key "focus_up" action NullAction()
    key "focus_down" action NullAction()
    
Is there a way to be selective about this? I thought using the "shelves_buttons" screen within the imagemap screen would help, but it acts the same as before :( Any ideas how I can get "shelves_buttons" to stay selectable by keys?

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: [SOLVED] Disable arrow keys on imagemaps

#6 Post by Alex »

Kinmoku wrote: Fri May 17, 2019 5:25 am ... Any ideas how I can get "shelves_buttons" to stay selectable by keys?
Never use it myself, but you could try to replace imagemap with a bunch of imagebuttons and set their keyboard_focus property to False - https://www.renpy.org/doc/html/style_pr ... oard_focus
So you won't need to disable focus mechanism at all.

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Help! Disable arrow keys on imagemaps only

#7 Post by Kinmoku »

Alex wrote: Fri May 17, 2019 11:15 am Never use it myself, but you could try to replace imagemap with a bunch of imagebuttons and set their keyboard_focus property to False - https://www.renpy.org/doc/html/style_pr ... oard_focus
So you won't need to disable focus mechanism at all.
Thanks Alex! :) Unfortunately, it's behaving a little...naughty. I think that's the best way to describe it.

For this test, I'm using another screen which is already set up with imagebuttons (instead of imagemap):

Code: Select all

screen yourside_imagebuttons:
    add "yourside"
    
    imagebutton idle Solid("#0000", xysize=(426, 232)) hover "jeansbutton" clicked Return('jeans') xpos 213 ypos 220 focus_mask None activate_sound "sounds/clothes.ogg" keyboard_focus False
    imagebutton idle Solid("#0000", xysize=(591, 216)) hover "clothesbutton" clicked Return('clothes') xpos 0 ypos 0 focus_mask None activate_sound "sounds/clothes.ogg" keyboard_focus False
    imagebutton idle Solid("#0000", xysize=(167, 57)) hover "flyerbutton" clicked Return('flyer') xpos 625 ypos 163 focus_mask None activate_sound "sounds/paper.ogg" keyboard_focus False
    imagebutton idle Solid("#0000", xysize=(337, 170)) hover "phonebutton" clicked Return('phone') xpos 899 ypos 325 focus_mask None activate_sound "sounds/item.ogg" keyboard_focus False
    imagebutton idle Solid("#0000", xysize=(681, 476)) hover "magazinesbutton" clicked Return('magazines') xpos 1239 ypos 28 focus_mask None activate_sound "sounds/magazines.ogg" keyboard_focus False

    imagebutton idle "images/left1.png" hover "leftbutton" clicked Return('shelfmap') xpos 20 ypos 420 focus_mask True activate_sound "sounds/button.ogg"
    imagebutton idle "images/leave_button1.png" hover "leavebutton" clicked Return('leaveattempt') xanchor 0.5 xpos 0.5 ypos 910 focus_mask True activate_sound "sounds/button.ogg"
On the first arrow key press, usually "jeansbutton" or "clothesbutton" will hover, but, when I press again, it won't select anymore (unless I move the cursor). So it half works, I guess, but if it's not 100%, I'm not keen on using it :(

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Help! Disable arrow keys on imagemaps only

#8 Post by Alex »

Kinmoku wrote: Mon May 20, 2019 4:19 am ...On the first arrow key press, usually "jeansbutton" or "clothesbutton" will hover, ...
And what if put your arrows buttons before other buttons in screen code? This might be that the fist button/hotspot in screen is focused by default.

User avatar
Kinmoku
Miko-Class Veteran
Posts: 591
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: VIDEOVERSE
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Re: Help! Disable arrow keys on imagemaps only

#9 Post by Kinmoku »

Alex wrote: Mon May 20, 2019 4:54 am
Kinmoku wrote: Mon May 20, 2019 4:19 am ...On the first arrow key press, usually "jeansbutton" or "clothesbutton" will hover, ...
And what if put your arrows buttons before other buttons in screen code? This might be that the fist button/hotspot in screen is focused by default.
Yes! :D Alex, you genius! It works! Thank you :)

Post Reply

Who is online

Users browsing this forum: No registered users