/    Sign up×
Community /Pin to ProfileBookmark

Assigning keyboard controls to buttons

I am a javascript novice and am wondering if it is possible to assign common keyboard functions to buttons. Such as can you make it so that when you click a button (<input type=”button”>) that is performs the same functions as if you were to hit keys on the keyboard?

The reason I ask is that I am working on a program for a class and we are trying to recreate the keyboard using buttons and javascript.

So when you click on the button “t” the letter t will appear in a text box. If you click the button “Shift” and then the button “t” it will place a T in the text box.

Any help is very appreciated!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliFeb 04.2005 — you don't have to use javascript for such purpose, you can use accesskey="t" attribute of button element.

<input type="button" value="process" onclick="alert('yayy');" accesskey="t"/>

just make sure that whatever accesskeys you assing to your controls thaty should not conflict with the browser or default OS accesskeys
Copy linkTweet thisAlerts:
@dlg0351authorFeb 07.2005 — Awesome! thanks!

One more question, is it possible to combine the actual pressing of the "Alt" key and "t" key and place the results to a html button?

In other words all you have to do is click the button on screen with the left mouse button, eliminating the need to use the keyboard.

Can you do this with one of the "Ctrl" keys? That way there won't be a conflict with the browser or default OS accesskeys?

Thanks ?
×

Success!

Help @dlg0351 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...