Created
March 24, 2014 10:03
-
-
Save ibmibmibm/9737519 to your computer and use it in GitHub Desktop.
Auto play 9007199254740992.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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