Skip to content

Instantly share code, notes, and snippets.

@ibmibmibm
Created March 24, 2014 10:03
Show Gist options
  • Save ibmibmibm/9737519 to your computer and use it in GitHub Desktop.
Save ibmibmibm/9737519 to your computer and use it in GitHub Desktop.
Auto play 9007199254740992.
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWebKit import *
import random
app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl("http://www.csie.ntu.edu.tw/~b01902112/9007199254740992/"))
#web.load(QUrl("http://gabrielecirulli.github.io/2048/"))
web.show()
keys = [Qt.Key_Right, Qt.Key_Down, Qt.Key_Left, Qt.Key_Up]
direction = 1
idx = 0
def action():
global idx, direction
key = keys[idx]
event = QKeyEvent(QEvent.KeyPress, key, Qt.NoModifier)
QCoreApplication.postEvent(web, event)
idx = (idx + direction) % 4
if random.randint(0, 99) == 0:
direction = -direction
timer = QTimer()
timer.timeout.connect(action)
timer.start(1)
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment