Webページ表示用の 「maitai.html」ソース

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<meta http-equiv="content-language" content="ja">
<title>MyTimelineTable</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.2.0/dist/leaflet.css" >
<script src="https://unpkg.com/leaflet@1.2.0/dist/leaflet.js"></script>
<style>
html,body{
   margin: 0px;
   padding: 0px;
}
#map {
   width: 1920px;
   height:1080px;
}
</style>
</head>

<body>
<div id="map"></div>

<script>
var map = L.map('map', {
   maxZoom: 4,
   minZoom: 1,
   crs: L.CRS.Simple
}).setView([0, 0], 0);

//地図の画像サイズ
var mapImageWidth =1920;
var mapImageHeight =1080;

var bounds = [[0, 960], [540, 0]]; //Leaflet の画像を配置する領域を指定
map.setMaxBounds(new L.LatLngBounds(bounds)); //表示可能範囲

//var imageUrl = 'image01.png'; //size 5616 x 3744
var imageBounds = [[0,960], [540,0]]; //初期表示範囲
// var image = L.imageOverlay(imageUrl,imageBounds);
// var kirikae =0;
var attributionStr = '&lt;a href="http://www.gsi.go.jp/kikakuchousei/kikakuchousei40182.html" target="_blank"&gt;国土地理院&lt;/a&gt;';

var imageFolderStr = 'maps1920x1080/';
var image00map =  L.imageOverlay(imageFolderStr+'00.png', imageBounds, {attribution: attributionStr});
var image01map =  L.imageOverlay(imageFolderStr+'01.png', imageBounds, {attribution: attributionStr});
var image02map =  L.imageOverlay(imageFolderStr+'02.png', imageBounds, {attribution: attributionStr});
var image03map =  L.imageOverlay(imageFolderStr+'03.png', imageBounds, {attribution: attributionStr});
var image04map =  L.imageOverlay(imageFolderStr+'04.png', imageBounds, {attribution: attributionStr});
var image05map =  L.imageOverlay(imageFolderStr+'05.png', imageBounds, {attribution: attributionStr});

document.onkeydown = keydown;
map.addLayer(image00map);
// map.fitBownd(bounds);

function keydown() {

  //target = document.getElementById("message");
  //target.innerHTML = "キーが押されました KeyCode :" + event.keyCode;

  //レイヤーが残っていたら容赦なく削除する
  if(map.hasLayer(image01map)){
      map.removeLayer(image01map);
      //target.innerHTML = "01レイヤーが削除されました:";
      }
  if(map.hasLayer(image02map)){
      map.removeLayer(image02map);
      //target.innerHTML = "02レイヤーが削除されました:";
      }
  if(map.hasLayer(image03map)){
      map.removeLayer(image03map);
      //target.innerHTML = "03レイヤーが削除されました:";
      }
  if(map.hasLayer(image04map)){
    map.removeLayer(image04map);
    //target.innerHTML = "03レイヤーが削除されました:";
  }
  if(map.hasLayer(image05map)){
    map.removeLayer(image05map);
    //target.innerHTML = "05レイヤーが削除されました:";
  }
  //以降、ここに繰り返して削除していく

  switch(event.keyCode){
    case 48: //red
    map.addLayer(image01map);
    break;

    case 49: //yellow
    map.addLayer(image02map);
    break;

    case 50:  //blue
    map.addLayer(image03map);
    break;

    case 51:  //green
    map.addLayer(image04map);
    break;

    case 52:  //Button L
    map.zoomOut(1);
    break;

    case 53:  //Button R
    map.zoomIn(1);
    break;

    case 65:  //A
    map.panBy(L.point(-30,0),{animate:false});
    break;
    case 87:  //W
    map.panBy(L.point(0,30),{animate:false});
    break;
    case 68:  //D
    map.panBy(L.point(30,0),{animate:false});
    break;
    case 88:  //X
    map.panBy(L.point(0,-30),{animate:false});
    break;
    default:
    break;
  }
}
</script>

</body>
</html>

USBコントローラーからの入力を対応させる[start.py」ソース

# for gamepad
import pygame
from pygame.locals import *
import pyautogui

# for web browser
import webbrowser

# for shutdown command
import os

from time import sleep

pygame.joystick.init()
try:
    j = pygame.joystick.Joystick(0) # create a joystick instance
    j.init() # init instance
    print (("Joystick" )+ j.get_name())
    print (("buttons")+str(j.get_numbuttons()))
except pygame.error:
    print ("No Joystick")

def main():
    pygame.init()

    # open web browser
    url="file:///home/pi/Desktop/maitai/maitaitable.html"
    #os.system('chromium-browser --app='+url)
    webbrowser.open(url)

    print('sleep start')
    sleep (10)
    print ('sleep end')

    #for set wait time
    dummyTimerWaitTime = 5
    dummyTimer = dummyTimerWaitTime


    #for reboot by using GamePad
    secretString ='etetetLRLL'
    currentSecretString ='aaaaaaaaaa'

    #for activate web browser window
    pyautogui.moveTo(860,540)
    pyautogui.click()
    pyautogui.press('f11')

    while 1:
        #pygame.time.wait(100)
        for e in pygame.event.get(): #check evernt
            if e.type == QUIT: #really quit?
                return
            if (e.type == KEYDOWN and
                e.key  == K_ESCAPE): # really esc?
                return
            # event check of Joystick
            if e.type == pygame.locals.JOYAXISMOTION: # 7
                if dummyTimer &amp;lt;= 0:
                    dummyTimer = dummyTimerWaitTime #reset
                    x , y = j.get_axis(0), j.get_axis(1)
                    if x &amp;gt; 0 and y ==0:
                        pyautogui.typewrite('d') #d
                    elif x&amp;lt;0 and y ==0 :
                        pyautogui.typewrite('a') #a
                    elif x ==0 and y &amp;gt;0 :
                        pyautogui.typewrite('w') #w
                    elif x==0 and y&amp;lt;0:
                        pyautogui.typewrite('x') #x
                else:
                    dummyTimer = dummyTimer -1

            elif e.type == pygame.locals.JOYBUTTONDOWN: # 10
                print (str(e.button)+('was pushed'))
                #autopy.mouse.move(20,30)
                if e.button == 0:
                    pyautogui.typewrite('0') #48 red
                elif e.button ==1:
                    pyautogui.typewrite('1') #49 yellow
                elif e.button ==2:
                    pyautogui.typewrite('2') #50 blue
                elif e.button ==3:
                   pyautogui.typewrite('3') #51 green
                elif e.button ==4:
                    pyautogui.typewrite('4') #52 left
                    currentSecretString += 'L'
                    #print (currentSecretString)
                elif e.button ==5:
                    pyautogui.typewrite('5') #53 right
                    currentSecretString += 'R'
                    #print (currentSecretString)
                elif e.button ==6:
                    currentSecretString += 'e'
                    #print (currentSecretString)
                elif e.button ==7:
                    currentSecretString += 't'
                    #print (currentSecretString)
            elif e.type == pygame.locals.JOYBUTTONUP: # 11
                print (str(e.button)+('was pushed'))
                pyautogui.typewrite('b')
                #dummyTimer = 30
                currentSecretString = currentSecretString[-10:11]
                print(currentSecretString)
                if currentSecretString == secretString:
                    print('shutdown')
                    os.system('sudo shutdown -h now')
                    break


if __name__ == '__main__': main()

# end of file

起動時に実行されるシェル「start.sh」ソース

#!/bin/sh
python3 /home/pi/Desktop/maitai/start.py