diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js
index 95084c8..a2287d3 100644
--- a/IPython/html/static/base/js/utils.js
+++ b/IPython/html/static/base/js/utils.js
@@ -365,6 +365,16 @@ IPython.utils = (function (IPython) {
var press_up = function() { press(keycodes.UP); };
var press_down = function() { press(keycodes.DOWN); };
+ var press_ctrl_enter = function() {
+ $(document).trigger($.Event('keydown', {which: keycodes.ENTER, ctrlKey: true}));
+ };
+
+ var press_shift_enter = function() {
+ $(document).trigger($.Event('keydown', {which: keycodes.ENTER, shiftKey: true}));
+ };
+ // trigger the ctrl-m shortcut followed by one of our keys
+ var press_ghetto = function(key) { presspress(key); };
+
var points_to_pixels = function (points) {
// A reasonably good way of converting between points and pixels.
@@ -423,6 +433,8 @@ IPython.utils = (function (IPython) {
press : press,
press_up : press_up,
press_down : press_down,
+ press_ctrl_enter : press_ctrl_enter,
+ press_shift_enter : press_shift_enter,
fixCarriageReturn : fixCarriageReturn,
autoLinkUrls : autoLinkUrls,
points_to_pixels : points_to_pixels,
diff --git a/IPython/html/tests/casperjs/test_cases/execute_code_cell.js b/IPython/html/tests/casperjs/test_cases/execute_code_cell.js
index f3ce449..4ba8356 100644
--- a/IPython/html/tests/casperjs/test_cases/execute_code_cell.js
+++ b/IPython/html/tests/casperjs/test_cases/execute_code_cell.js
@@ -30,7 +30,7 @@ casper.notebook_test(function () {
var cell = IPython.notebook.get_cell(0);
cell.set_text('a=11; print(a)');
cell.clear_output()
- $(document).trigger($.Event('keydown', {which: 13, ctrlKey: true}))
+ IPython.utils.press_ctrl_enter();
});
this.waitFor(function () {
@@ -48,4 +48,28 @@ casper.notebook_test(function () {
})
this.test.assertEquals(result, '11\n', 'cell execute (using ctrl-enter)')
});
+
+ // do it again with the keyboard shortcut
+ this.thenEvaluate(function () {
+ var cell = IPython.notebook.get_cell(0);
+ cell.set_text('a=12; print(a)');
+ cell.clear_output()
+ IPython.utils.press_shift_enter();
+ });
+
+ this.waitFor(function () {
+ return this.evaluate(function get_output() {
+ var cell = IPython.notebook.get_cell(0);
+ return cell.output_area.outputs.length != 0;
+ })
+ });
+
+ this.then(function () {
+ var result = this.evaluate(function () {
+ var cell = IPython.notebook.get_cell(0);
+ var output = cell.output_area.outputs[0].text;
+ return output;
+ })
+ this.test.assertEquals(result, '12\n', 'cell execute (using shift-enter)')
+ });
});