Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8964291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:33:18+00:00 2026-06-15T16:33:18+00:00

I have a simple, sort of GUI code shown below. This test_keypress function creates

  • 0

I have a simple, sort of GUI code shown below.
This “test_keypress” function creates a figure, and it responses to the keypress (space).

Now, I want to add a constraint so that Matlab accepts only one keypress for a certain period of time (say, 1 second).
In other words, I want to reject a keypress if it happens within 1 sec after the previous keypress occurred.

How can I do that?

function test_keypress

f = figure;
set(f,'KeyPressFcn',@figInput);
imshow(ones(200,200,3));

end


function figInput(src,evnt)

if strcmp(evnt.Key,'space')
    imshow(rand(200,200,3));
end

end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:33:19+00:00Added an answer on June 15, 2026 at 4:33 pm

    You can store the current time, and only evaluate the imshow command if the key-press occurs at least 100 seconds after the last one.

    function test_keypress
    
    f = figure;
    set(f,'KeyPressFcn',@figInput);
    imshow(ones(200,200,3));
    
    %# initialize time to "now"
    set(f,'userData',clock);
    
    end
    
    
    function figInput(src,evnt)
    
    currentTime = clock;
    %# get last time
    lastTime = get(src,'UserData');
    
    %# show new figure if the right key has been pressed and at least
    %# 100 seconds have elapsed
    if strcmp(evnt.Key,'space') && etime(lastTime,currentTime) > 100
        imshow(rand(200,200,3));
        %# also update time
        set(src,'UserData',currentTime)
    end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple f# quick sort function defined as: let rec qsort(xs:List<int>) =
I have implemented a simple parallel merge sort algorithm in Java. This cuts the
I have this simple piece of code public ActionResult ListToGrid(string field, string direction) {
This is a weired problem, I have implemented simple quick sort as follows.. static
I have a simple question, not able to sort it out. I have a
I have a sql statement I am using a simple sort such as the
I have a simple application that I would like to sort of automate via
I have some simple jQuery written to sort some elements based on a numerical
How do I just do a simple sort in matlab. I always have to
I'm trying to get a simple sort function going using anonymous functions. One each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.