Zhanseit2014-04-23 08:54:46
Zhanseit, 2014-04-23 08:54:46

A combination of a physical (real) button and a program?

Hello everyone, I'm not very versed in the field of circuitry yet, but I have basic knowledge, here's the problem, I made a website in PHP and it's ready for use, there I have a games section, simple games like choose one of the answers below, so here I am I would like to use live real buttons, two buttons in one have the function of choosing the right answers, the other, respectively, choosing the right one, 4d108ff739b94d568c67910bf456d82a.jpg
how can I combine it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Vitaly Zheltyakov, 2014-04-23

The easiest option is to remake a USB mouse and handle the onMouseUp events on the site

m-haritonov, 2014-04-23

In your case, JavaScript is responsible for processing keystrokes, not PHP (because it is JavaScript that is executed on the client's computer). I think you should write JavaScript handlers that, upon pressing certain keyboard key combinations (say, Ctrl + 1 and Ctrl + 2), would perform the required actions (selecting an answer option and submitting the form). And two physical buttons, when pressed, would simply send codes to the browser corresponding to pressing Ctrl + 1 and Ctrl + 2 on the keyboard.
An example of JavaScript code for handling keystrokes:

<!DOCTYPE html>
    <script type="text/javascript">
      document.addEventListener('keydown', function(e){
        // Ctrl+1
        if (e.ctrlKey && e.which === 49)
          alert('Выбор следующего ответа');
      document.addEventListener('keydown', function(e){
        // Ctrl+2
        if (e.ctrlKey && e.which === 50)
          alert('Отправка формы с выбранным ответом');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question